package com.homwee.factory.tvtool;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;


import com.homwee.factory.R;
import com.mediatek.twoworlds.factory.MtkTvFApiAudio;
import com.mediatek.twoworlds.factory.MtkTvFApiAudioBase;
import com.mediatek.twoworlds.factory.MtkTvFApiInformation;
import com.mediatek.twoworlds.factory.MtkTvFApiInformationBase;
import com.mediatek.twoworlds.factory.MtkTvFApiSystem;
import com.mediatek.twoworlds.factory.common.MtkTvFApiAudioTypes.AudioInputSource;
import com.mediatek.twoworlds.factory.common.MtkTvFApiAudioTypes.BasicSndParams;
import com.mediatek.twoworlds.factory.common.MtkTvFApiAudioTypes.BasicSndStatus;
import com.mediatek.twoworlds.factory.common.MtkTvFApiAudioTypes.BasicSoundEnableStatus;
import com.mediatek.twoworlds.factory.common.MtkTvFApiAudioTypes.EnumAoutPath;
import com.mediatek.twoworlds.factory.common.MtkTvFApiAudioTypes.EnumAudOutputType;
import com.mediatek.twoworlds.factory.common.MtkTvFApiAudioTypes.EnumBasicSoundType;
import com.mediatek.twoworlds.factory.common.MtkTvFApiAudioTypes.EnumSoundMode;
import com.mediatek.twoworlds.factory.common.MtkTvFApiAudioTypes.SoundEffectParams;
import com.mediatek.twoworlds.factory.common.inimanager.MtkTvFApiAudioIniManager;
import com.mediatek.twoworlds.factory.common.inimanager.MtkTvFApiAudioIniManager.MTKTV_FAPI_INI_TYPE_AUDIO_ENUM;
import com.mediatek.twoworlds.factory.common.inimanager.MtkTvFApiAudioIniManager.MTKTV_FAPI_KEY_TYPE_AUDIO_ENUM;
import com.mediatek.twoworlds.factory.model.MtkTvFApiSysFactorySvcCmd_e;
import com.mediatek.twoworlds.tv.MtkTvConfig;
import com.mediatek.twoworlds.tv.MtkTvInputSource;
import com.mediatek.twoworlds.tv.MtkTvInputSourceBase;
import com.mediatek.twoworlds.tv.common.MtkTvConfigType;
import com.mediatek.twoworlds.tv.common.MtkTvConfigTypeBase;

import android.app.Activity;
import android.app.Service;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Environment;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.storage.StorageManager;
import android.os.SystemProperties;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.InputDevice;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.View.OnKeyListener;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.Spinner;
import android.widget.Switch;
import android.widget.TabHost;
import android.widget.TabWidget;
import android.widget.TextView;
import android.widget.Toast;

import com.homwee.factory.tvtool.AQLayout;
import com.homwee.factory.TvToolService;
import com.homwee.factory.util.Contants;



public class AQService extends Service {

	WindowManager mWindowManager;
	LayoutInflater mInflater;
	private long mExitTime;
	WindowManager.LayoutParams wmParams_aq;
	TabHost mTabHost_aq;
	TabWidget mTabWidget_aq;
	View  tab_prescaler, tab_others, tab_peq;
	Button AQExportData;
	Button bt_exit_aq;

	LinearLayout ll_aq;
	boolean isInit;
	private ArrayList<MtkTvInputSourceBase.InputSourceRecord> inputList = new ArrayList<MtkTvInputSourceBase.InputSourceRecord>();
	private ArrayList<String> mUiSourceList = new ArrayList<String>();
	
	
	private final boolean AQ_MIC_OFF = true;  //无MIC  关
	private String[] SourceName ;
	public int SOUND_MODE_ID = 0;
	public int SRC_ID = 0;
	
	
    private String HDMI1Uri =	"content://android.media.tv/passthrough/com.mediatek.tvinput%2F.hdmi.HDMIInputService%2FHW4";
    private String ComponentUri =	"content://android.media.tv/passthrough/com.mediatek.tvinput%2F.component.ComponentInputService%2FHW2";  
    private String CompositeUri =	"content://android.media.tv/passthrough/com.mediatek.tvinput%2F.composite.CompositeInputService%2FHW1";  
    private String VgaUri =	"content://android.media.tv/passthrough/com.mediatek.tvinput%2F.vga.VGAInputService%2FHW3";    
    private String TVUri =		"content://android.media.tv/channel";
    private String HDMI2Uri =	"content://android.media.tv/passthrough/com.mediatek.tvinput%2F.hdmi.HDMIInputService%2FHW5";  
    private String HDMI3Uri =	"content://android.media.tv/passthrough/com.mediatek.tvinput%2F.hdmi.HDMIInputService%2FHW6";
	private Map<String, String> sourceMap = new HashMap<String, String>();
//	private String outAQFile[] = {"BasicSound_ATV.ini", "BasicSound_CVBS.ini", "BasicSound_DTV.ini", "BasicSound_Default.ini", "BasicSound_HDMI.ini", "BasicSound_MM.ini", "BasicSound_Movie.ini", "BasicSound_Music.ini", "BasicSound_News.ini", "BasicSound_Sports.ini", "BasicSound_Standard.ini", "BasicSound_User.ini", "BasicSound_Vivid.ini"};
	private String outinputAQFile[] = {"BasicSound_ATV.ini", "BasicSound_CVBS.ini", "BasicSound_DTV.ini", "BasicSound_Default.ini", "BasicSound_HDMI.ini", "BasicSound_MM.ini"};
	private String outmodeAQFile[] = {"BasicSound_Movie.ini", "BasicSound_Music.ini", "BasicSound_News.ini", "BasicSound_Sports.ini", "BasicSound_Standard.ini", "BasicSound_User.ini", "BasicSound_Vivid.ini"};
	
    @Override
	public void onCreate() {
		// TODO Auto-generated method stub
		isInit = true;
		MtkTvInputSourceBase sourceBase = new MtkTvInputSourceBase();
		int totalSource = sourceBase.getInputSourceTotalNumber();
		initSourceName();
		SourceName = new String[totalSource];
		for(int i = 0; i < totalSource; i++){
		    SourceName[i] = mUiSourceList.get(i);
//		    Log.d(TAG,"source name "+record.getSourceName()+" sourceid "+record.getId());
		}
		if(!mUiSourceList.contains("ATV")){
			mUiSourceList.set(0, "TV");
			sourceMap.put("TV", TVUri);
			SourceName[0]="TV";
		}
		
		mWindowManager = (WindowManager) getApplication().getSystemService(getApplication().WINDOW_SERVICE);
		mInflater = LayoutInflater.from(getApplication());
		
		
		//Check if there is a U disk
		CheckSDCardSwitchOn();
		
		//Show the AQ main interface
		createAQView();
		mWindowManager.addView(mTabHost_aq, wmParams_aq);

		isInit = false;
		StaticValues.aqServiceInstance = this;
		StaticValues.bSaveAQAndExit = false;
		StaticValues.bSavePQAndExit = false;
		super.onCreate();
	}

	@Override
	public void onDestroy() {
		// TODO Auto-generated method stub
		StaticValues.bSaveAQAndExit = false;
		// Toast.makeText(this, "service onDestroy", Toast.LENGTH_SHORT).show();
		if (mTabHost_aq != null) {
			// mWindowManager.removeView(mTabHost_pq);
		}
		Intent i = new Intent(this, TvToolService.class);
		startService(i);
		super.onDestroy();
	}

	@Override
	public IBinder onBind(Intent arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	//AlertDialog
	protected void OpenTipDialog(String strTitle, String strInfo) {
		// TODO Auto-generated method stub
		/*
		 * new AlertDialog.Builder().setTitle(strTitle).setMessage(strInfo)
		 * .setIcon(android.R.drawable.ic_dialog_info) .setPositiveButton("确定",
		 * null) .show();
		 */
		Toast.makeText(this, strTitle + ": " + strInfo, Toast.LENGTH_LONG)
				.show();
	}

	// Determine whether the U disk is inserted
	protected boolean CheckSDCardSwitchOn() {
		// TODO Auto-generated method stub
				
		
		try {
			StorageManager mStorageManager = (StorageManager) getSystemService(STORAGE_SERVICE);
			Class<?>[] paramClasses = {};
			Object[] params = {};
			Method getVolumePathsMethod = StorageManager.class.getMethod("getVolumePaths", paramClasses);
			String[] paths = (String[]) getVolumePathsMethod.invoke(mStorageManager, params);		
			int size = 0;
			for(String str:paths){
				 Log.i(TAG,"myprint:"+str); 
				 size++;
		  	}
			
			if(size<=1){
				Log.i(TAG, "U disk was not found");
				return false;
			}else{
				SDPath = paths[1];
				Log.i(TAG, "U disk was found");
				Log.i(TAG, "SDPath = " + SDPath);
				return true;			
			     }			
			
		} catch (Exception e) {
		    Log.e(TAG, "CheckSDCardSwitchOn() failed", e);
		    return false;
		}
		
		
		
		
		
	}

	TextView tv_indicator0, tv_indicator1, tv_indicator2, tv_indicator3,
			tv_indicator4, tv_indicator5, tv_indicator6, tv_indicator7;
	
    //AQ main interface display
	private void createAQView() {
		wmParams_aq = new WindowManager.LayoutParams();
		wmParams_aq.type = LayoutParams.TYPE_PHONE;
		wmParams_aq.format = PixelFormat.RGBA_8888;
		wmParams_aq.gravity = Gravity.LEFT | Gravity.TOP;
		wmParams_aq.x = 0;
		wmParams_aq.y = 0;
		wmParams_aq.width = WindowManager.LayoutParams.MATCH_PARENT;
		wmParams_aq.height = WindowManager.LayoutParams.MATCH_PARENT;

		// mTabHost_aq = (TabHost) mInflater.inflate(R.layout.aq, null);
		mTabHost_aq = new AQLayout(getApplicationContext(), this);

		mTabHost_aq.setup();


		final LinearLayout ll2 = (LinearLayout) mInflater.inflate(
				R.layout.tab_cell, null);
		((ImageView) ll2.findViewById(R.id.tab_iv))
				.setImageResource(R.drawable.aq_prescaler);
		((TextView) ll2.findViewById(R.id.tab_tv)).setText(getString(R.string.aq_input_gain));

		final LinearLayout ll3 = (LinearLayout) mInflater.inflate(
				R.layout.tab_cell, null);
		((ImageView) ll3.findViewById(R.id.tab_iv))
				.setImageResource(R.drawable.aq_eq);
		((TextView) ll3.findViewById(R.id.tab_tv)).setText(getString(R.string.aq_peq));
		
		
		final LinearLayout ll6 = (LinearLayout) mInflater.inflate(
				R.layout.tab_cell, null);
		((ImageView) ll6.findViewById(R.id.tab_iv))
				.setImageResource(R.drawable.aq_amp);
		((TextView) ll6.findViewById(R.id.tab_tv)).setText(getString(R.string.aq_other));

		

		mTabHost_aq.addTab(mTabHost_aq.newTabSpec("tab_prescaler")
				.setIndicator(ll2).setContent(R.id.ll_aq_prescaler));
		
		mTabHost_aq.addTab(mTabHost_aq.newTabSpec("tab_peq")
				.setIndicator(ll3).setContent(R.id.ll_aq_peq));

		mTabHost_aq.addTab(mTabHost_aq.newTabSpec("tab_others")
				.setIndicator(ll6).setContent(R.id.ll_aq_others));


		//Set background color
		mTabHost_aq.setBackgroundColor(Color.parseColor("#a0000000"));
		mTabWidget_aq = mTabHost_aq.getTabWidget();
		mTabWidget_aq.setBackgroundColor(Color.BLACK);
		// mTabWidget_pq.getChildAt(0).setBackgroundResource(R.drawable.ic_launcher_src);

		 //Focus display
		mTabHost_aq.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
			public void onTabChanged(String tabId) {
//				ButtonExportData.setNextFocusLeftId(R.id.ExportData);
				switchFocus = true;
				// Toast.makeText(AQService.this, tabId,
				// Toast.LENGTH_SHORT).show();


				if (tabId.equals("tab_prescaler")) {
					ll2.setBackgroundResource(R.drawable.tabcell_bg);
					ll3.setBackgroundResource(R.drawable.seekbar_bg);
					ll6.setBackgroundResource(R.drawable.seekbar_bg);
				}
                 
				if (tabId.equals("tab_peq")) {
					ll2.setBackgroundResource(R.drawable.seekbar_bg);
					ll3.setBackgroundResource(R.drawable.tabcell_bg);
					ll6.setBackgroundResource(R.drawable.seekbar_bg);
				}


				if (tabId.equals("tab_others")) {
					ll2.setBackgroundResource(R.drawable.seekbar_bg);
					ll3.setBackgroundResource(R.drawable.seekbar_bg);
					ll6.setBackgroundResource(R.drawable.tabcell_bg);
					focusEditText = edit_AQID;
				}


			}

		});


		tab_prescaler = mTabWidget_aq.getChildTabViewAt(0);
		tab_prescaler.setId(0);

		tab_peq = mTabWidget_aq.getChildTabViewAt(1);
		tab_peq.setId(1);

		tab_others = mTabWidget_aq.getChildTabViewAt(2);
		tab_others.setId(2);

		//Microphone array
		if(AQ_MIC_OFF){
			ll6.setNextFocusRightId(0);
			ll6.setNextFocusLeftId(1);
		}	
		

		tab_prescaler.setOnFocusChangeListener(new OnFocusChangeListener() {

			@Override
			public void onFocusChange(View view, boolean isFocused) {
				// TODO Auto-generated method stub
				if (isFocused) {
					if (switchFocus) {
						mTabHost_aq.setCurrentTab(0);
					} else {
						focusEditText.requestFocus();
					}
				}
			}

		});
		
		tab_peq.setOnFocusChangeListener(new OnFocusChangeListener() {

			@Override
			public void onFocusChange(View view, boolean isFocused) {
				// TODO Auto-generated method stub
				if (isFocused) {
					if (switchFocus) {
						mTabHost_aq.setCurrentTab(1);
					} else {
						focusEditText.requestFocus();
					}
				}
			}

		});
	
	
		tab_others.setOnFocusChangeListener(new OnFocusChangeListener() {

			@Override
			public void onFocusChange(View view, boolean isFocused) {
				// TODO Auto-generated method stub
				if (isFocused) {
					if (switchFocus) {
						mTabHost_aq.setCurrentTab(2);
					} else {
						focusEditText.requestFocus();
					}
				}
			}

		});

		/*
		 * bt_exit_aq = (Button) mTabHost_aq.findViewById(R.id.bt_exit_aq);
		 * bt_exit_aq.setOnClickListener(new OnClickListener() {
		 * 
		 * @Override public void onClick(View arg0) { // TODO Auto-generated
		 * method stub mWindowManager.removeView(mTabHost_aq); Intent i = new
		 * Intent(AQService.this, TVtoolService.class); startService(i);
		 * stopSelf(); } });
		 */
		
		//Initialize AQ data£»
		initAQ();
	}

	private void initAQ() {
		
		//If you do not read the data from the file under the hwcfg/aq/aq/[product]_aq.ini path, the default data is the current global temporary data
//		readOrCreateAQFile();
		
		//Get power amplifier type
//		getAmpType();
		setCurrentAudioSrcByinputsource();
		
		//Gets the current sound mode
		getSoundMode();
		
		//Gets the current source ID
		getCurrentSourceID();
		
		initAMP();
		initPrescaler();
		initpeq();
		initOthers();
		initexport();
		setFocusOrder();
	}

	/*
	 * private OnClickListener bt_exportData_aq_listener = new OnClickListener()
	 * {
	 * 
	 * @Override public void onClick(View v) {
	 * 
	 * } };
	 */
    
	//If you do not read the data from the file under the hwcfg/aq/aq/[product]_aq.ini path, the default data is the current global temporary data
	public void readOrCreateAQFile() {
		// U PATH
		// SDPath= Environment.getExternalStorageDirectory().getPath();//+ "//";
		// get product name
		try {
			  CurProductName = MtkTvFApiInformation.getInstance().getTvInformation().productType.name();//mTvMiscManager.getProductName();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if (CurProductName.isEmpty()) {
			CurProductName = "UnkonwProduct";
		}
		Toast.makeText(AQService.this, getString(R.string.aq_cur_product)+CurProductName, Toast.LENGTH_LONG)
				.show();
		Log.v(TAG, CurProductName);

		try {
			OutAQinifilePath = LocalPath + "aq/" + CurProductName + "_aq.ini";
			OutAQinifileSDCardPath = SDPath + "/" + CurProductName + "_aq.ini";

			OutMICinifilePath = LocalPath + "mic/" + CurProductName
					+ "_mic.ini";
			OutMICinifileSDCardPath = SDPath + "/" + CurProductName
					+ "_mic.ini";

			Log.v(TAG, OutAQinifilePath);
			Log.v(TAG, OutAQinifileSDCardPath);
			Log.v(TAG, OutMICinifilePath);
			Log.v(TAG, OutMICinifileSDCardPath);

			if (!InitAQdata()) {// read(if exists) or create aq.ini file
				OpenTipDialog("error", "Initialization error!Please reopen it!");
				Toast.makeText(AQService.this, getString(R.string.aq_init_error),
						Toast.LENGTH_LONG).show();
				stopSelf();
				// android.os.Process.killProcess(android.os.Process.myPid());
			}
			// InitMicData();

		} catch (Exception e) {

			e.printStackTrace();

		}
	}

	public void getAmpType() {
		try {
			int ampTypeIndex = StaticValues.CHTV_AMP_IC_NULL;
			
//			int ampTypeIndex = TVManager.getInstance(AQService.this)
//					.getMiscManager().getCurrentProductAmpICType();

			Log.v("AQ_ampTypeIndex", "" + ampTypeIndex);
			if (ampTypeIndex == StaticValues.CHTV_AMP_IC_5707) {
				AmpIndex = 1;
			} else if (ampTypeIndex == StaticValues.CHTV_AMP_IC_5711_2CH1 || ampTypeIndex == StaticValues.CHTV_AMP_IC_5711_2CH) {
				AmpIndex = 0;
			}else if (ampTypeIndex==StaticValues.CHTV_AMP_IC_5719){    //wql 2014-9-30 
				AmpIndex = 2;
			} else if (ampTypeIndex == StaticValues.CHTV_AMP_IC_5711_AND_5711 ) {
				both5711 = true;
			} else if (ampTypeIndex == StaticValues.CHTV_AMP_IC_5707_AND_5711 )
			{
				bothAmp = true;
			}else if(ampTypeIndex == StaticValues.CHTV_AMP_IC_5719_AND_5719)
			{
				both5719 = true;
			}else
			{
				AmpIndex = 2;
			}	
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
		
//	public enum CHENUMAudioMode {
//		CH_SOUND_MODE_STANDARD, // standard
//		CH_SOUND_MODE_MUSIC,    // Music
//		CH_SOUND_MODE_MOVIE,  // Theatre
//		CH_SOUND_MODE_SPORT,      // News
//		CH_SOUND_MODE_USER      // User
//	}
//	
	public void getSoundMode() {
		try {
			
			SOUND_MODE_ID = MtkTvConfigTypeBase.AUDIO_MODE_USER;//CHENUMAudioMode.CH_SOUND_MODE_STANDARD;
//			currentSoundMode = TVManager.getInstance(AQService.this)
//					.getMiscManager().getContextualModel();
			SOUND_MODE_ID = MtkTvConfig.getInstance().getConfigValue(MtkTvConfigTypeBase.CFG_AUD_SOUND_MODE);//mTvMiscManager.getAudioMode();
			
//			if(currentSoundMode == CHENUMAudioMode.CH_SOUND_MODE_USER){
//				currentSoundMode = CHENUMAudioMode.CH_SOUND_MODE_STANDARD;
//			}	
			//currentSoundMode = mTvAudioManager.getSoundMode();
			Log.v(TAG, "my sound mode=" + SOUND_MODE_ID);
			
//			SOUND_MODE_ID=currentSoundMode.ordinal();
//			switch (currentSoundMode) {
//			case EnumSoundMode.E_STANDARD.ordinal():
//				SOUND_MODE_ID = 0;
//				break;
//			case StaticValues.CHTV_CONTEXTUAL_MODEL_MOVIE:
//				SOUND_MODE_ID = 1;
//				break;
//			case StaticValues.CHTV_CONTEXTUAL_MODEL_UMAX:
//				SOUND_MODE_ID = 2;
//				break;
//			case StaticValues.CHTV_CONTEXTUAL_MODEL_READING:
//				SOUND_MODE_ID = 3;
//				break;
//			case StaticValues.CHTV_CONTEXTUAL_MODEL_MV:
//				SOUND_MODE_ID = 4;
//				break;
//			case StaticValues.CHTV_CONTEXTUAL_MODEL_SPORTS:
//				SOUND_MODE_ID = 5;
//				break;
//			case StaticValues.CHTV_CONTEXTUAL_MODEL_GAME:
//				SOUND_MODE_ID = 6;
//				break;	
//			case StaticValues.CHTV_CONTEXTUAL_MODEL_FOOTBALL:
//				SOUND_MODE_ID = 0;
//				break;		
//			default:
//				SOUND_MODE_ID = 0;
//				break;
//
//			}
			Log.v(TAG, String.valueOf(SOUND_MODE_ID) + "test");

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void getCurrentSourceID() {
	try {
		
		String currentSource = MtkTvInputSourceBase.INPUT_TYPE_ATV;//MtkTvInputSourceBase.InputSourceRecord.INPS_TYPE_NUMERICAL_TV;//EnumInputSource.E_INPUT_SOURCE_ATV;

		try {
			currentSource = MtkTvInputSource.getInstance().getCurrentInputSourceName();//mTvCommonManager.getCurrentInputSource();
//			currentSource = TVManager
//					.getInstance(AQService.this)
//					.getSourceManager()
//					.getCurInputSource(
//							EnumPipInputSource.E_MAIN_INPUT_SOURCE);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		Log.d(TAG,"currentSource "+currentSource);
//		switch (currentSource) {
//		case MtkTvInputSourceBase.INPUT_TYPE_ATV: // /<TV input
//			SRC_ID = 0;
//			break;
//		case E_INPUT_SOURCE_DTV: // /<DTV
//		case E_INPUT_SOURCE_DTV2: // /<DTV
//		case E_INPUT_SOURCE_DTV3: // /<DTV
//			SRC_ID = 1;
//			break;
//		case E_INPUT_SOURCE_CVBS: // /<AV 1
//		case E_INPUT_SOURCE_CVBS2: // /<AV 2
//		case E_INPUT_SOURCE_CVBS3: // /<AV 3
//		case E_INPUT_SOURCE_CVBS4: // /<AV 4
//		case E_INPUT_SOURCE_CVBS_MAX:// /<AV max
//		case E_INPUT_SOURCE_SVIDEO: // /<S-video 1
//		case E_INPUT_SOURCE_SVIDEO2: // /<S-video 2
//		case E_INPUT_SOURCE_SVIDEO_MAX: // /<S-video max
//		case E_INPUT_SOURCE_SCART: // /<Scart 1
//		case E_INPUT_SOURCE_SCART2: // /<Scart 2
//		case E_INPUT_SOURCE_SCART_MAX: // /<Scart max
//			SRC_ID = 2;
//			break;
//		case E_INPUT_SOURCE_YPBPR: // /<Component 1
//		case E_INPUT_SOURCE_YPBPR2: // /<Component 2
//		case E_INPUT_SOURCE_YPBPR_MAX: // /<Component max
//			SRC_ID = 3;
//			break;
//		case E_INPUT_SOURCE_VGA: // /<VGA input
//		case E_INPUT_SOURCE_VGA2: // /<VGA input
//		case E_INPUT_SOURCE_VGA3: // /<VGA input	
//			SRC_ID = 4;
//			break;
//		case E_INPUT_SOURCE_HDMI: // /<HDMI 1
//		case E_INPUT_SOURCE_HDMI2: // /<HDMI 2
//		case E_INPUT_SOURCE_HDMI3: // /<HDMI 3
//		case E_INPUT_SOURCE_HDMI4: // /<HDMI 4
//		case E_INPUT_SOURCE_HDMI_MAX: // /<HDMI max
//		case E_INPUT_SOURCE_DVI: // /<DVI 1
//		case E_INPUT_SOURCE_DVI2: // /<DVI 2
//		case E_INPUT_SOURCE_DVI3: // /<DVI 2
//		case E_INPUT_SOURCE_DVI4: // /<DVI 4
//		case E_INPUT_SOURCE_DVI_MAX: // /<DVI max
//			SRC_ID = 5;
//			break;
//			
//		case  E_INPUT_SOURCE_STORAGE: // /<MEDIAPLAYER
//		case  E_INPUT_SOURCE_STORAGE2:
//			SRC_ID = 6;
//			break;
////		case E_INPUT_SOURCE_NETPLAYER:
////			SRC_ID = 7;
//			
//		case E_INPUT_SOURCE_NUM: // /<number of the source
//		case E_INPUT_SOURCE_NONE: // /<NULL input
//			SRC_ID = 7;
//			break;
//		default:
//			SRC_ID = 7;
//			break;
//
//		}
//		if(currentSource.equals(MtkTvInputSourceBase.INPUT_TYPE_ATV)){
//			SRC_ID = 0;
//		} else if(currentSource.equals(MtkTvInputSourceBase.INPUT_TYPE_DTV)){
//			SRC_ID = 1;
//		} else if(currentSource.equals(MtkTvInputSourceBase.INPUT_TYPE_SCART)
//				|| currentSource.equals(MtkTvInputSourceBase.INPUT_TYPE_AV)
//				|| currentSource.equals(MtkTvInputSourceBase.INPUT_TYPE_COMPOSITE)
//				||currentSource.equals(MtkTvInputSourceBase.INPUT_TYPE_SVIDEO)){
//			SRC_ID = 2;
//		} else if(currentSource.equals(MtkTvInputSourceBase.INPUT_TYPE_COMPONENT)){
//			SRC_ID = 3;
//		} else if(currentSource.equals(MtkTvInputSourceBase.INPUT_TYPE_VGA)){
//			SRC_ID = 4;
//		} else if(currentSource.equals(MtkTvInputSourceBase.INPUT_TYPE_HDMI)){
//			SRC_ID = 5;
//		} 
		for(int i = 0; i < mUiSourceList.size(); i++){
			if(mUiSourceList.get(i).equalsIgnoreCase(currentSource)){
				SRC_ID = i;
				break;
			}
		}

	    //spinner_src.setSelection(SRC_ID, true);
		//spinner_output.setSelection(SRC_ID, true);
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

	}
	
	public boolean InitAQdata() {
		
		//readDTSInfo(OutAQinifilePath);
		
		try {
			File file_aq_ini = new File(OutAQinifilePath);
			INIFile inif_aq = new INIFile("AQ_aq", CurProductName);

			int i = 0;

			if (file_aq_ini.exists()) {
				Log.v(TAG, "the file  is exists!");

				inif_aq.openINI(OutAQinifilePath);

				for (String curSectionName : sectionNmaes) {
					i = 0;

					if (curSectionName.equalsIgnoreCase(sectionNmaes[0])) {
						for (String curKey : keyIniVersion) {
							valueIniVersion[i++] = inif_aq.GetValue(
									curSectionName, curKey);
						}
						continue;
					}

					if (curSectionName.equalsIgnoreCase(sectionNmaes[1])) {
						for (String curKey : keySourceSpeakerPrescaler) {
							valueSourceSpeakerPrescaler[i++] = inif_aq
									.GetValue(curSectionName, curKey);
						}
						continue;
					}

					if (curSectionName.equalsIgnoreCase(sectionNmaes[2])) {
						for (String curKey : keySoundModeSetting) {
							valueSoundModeSetting[i++] = inif_aq.GetValue(
									curSectionName, curKey);
						}
						continue;
					}

					if (curSectionName.equalsIgnoreCase(sectionNmaes[3])) {
						for (String curKey : keySound_NonLinear_Source) {
							valueSound_NonLinear_Source[i++] = inif_aq
									.GetValue(curSectionName, curKey);
						}
						continue;
					}

					if (curSectionName.equalsIgnoreCase(sectionNmaes[4])) {
						for (String curKey : keySound_NonLinear_Source_Market) {
							valueSound_NonLinear_Source_Market[i++] = inif_aq
									.GetValue(curSectionName, curKey);
						}
						continue;
					}

					if (curSectionName.equalsIgnoreCase(sectionNmaes[5])) {
						for (String curKey : keyVIRTUAL_SURROUND) {
							valueVIRTUAL_SURROUND[i++] = inif_aq.GetValue(
									curSectionName, curKey);
						}
						continue;
					}

					if (curSectionName.equalsIgnoreCase(sectionNmaes[6])) {
						for (String curKey : keyAVOutPathGain) {
							valueAVOutPathGain[i++] = inif_aq.GetValue(
									curSectionName, curKey);
						}
						continue;
					}

					if (curSectionName.equalsIgnoreCase(sectionNmaes[7])) {
						for (String curKey : keySPDIFOutPathGain) {
							valueSPDIFOutPathGain[i++] = inif_aq.GetValue(
									curSectionName, curKey);
						}
						continue;
					}
					
					if (curSectionName.equalsIgnoreCase(sectionNmaes[8])) {
						for (String curKey : keyLimiterThreshold) {
							valueLimiterThreshold[i++] = inif_aq.GetValue(
									curSectionName, curKey);
						}
						continue;
					}

					if (curSectionName.equalsIgnoreCase(sectionNmaes[9])) {
						for (String curKey : keyPEQ_PARAM) {
							valuePEQ_PARAM[i++] = inif_aq.GetValue(
									curSectionName, curKey);
						}
						continue;
					}

					if (curSectionName.equalsIgnoreCase(sectionNmaes[10])) {
						for (String curKey : keyAUDIO_NR_THR) {
							valueAUDIO_NR_THR[i++] = inif_aq.GetValue(
									curSectionName, curKey);
						}
						continue;
					}
				}

			} else {
				Log.v(TAG, "the file  not exists!");
				file_aq_ini.createNewFile();

				for (String curSectionName : sectionNmaes) {
					i = 0;

					if (curSectionName.equalsIgnoreCase(sectionNmaes[0])) {
						for (String curKey : keyIniVersion) {
							inif_aq.SetValue(curSectionName, curKey,
									valueIniVersion[i++]);
						}
						continue;
					}

					if (curSectionName.equalsIgnoreCase(sectionNmaes[1])) {
						for (String curKey : keySourceSpeakerPrescaler) {
							inif_aq.SetValue(curSectionName, curKey,
									valueSourceSpeakerPrescaler[i++]);
						}
						continue;
					}

					if (curSectionName.equalsIgnoreCase(sectionNmaes[2])) {
						for (String curKey : keySoundModeSetting) {
							inif_aq.SetValue(curSectionName, curKey,
									valueSoundModeSetting[i++]);
						}
						continue;
					}

					if (curSectionName.equalsIgnoreCase(sectionNmaes[3])) {
						for (String curKey : keySound_NonLinear_Source) {
							inif_aq.SetValue(curSectionName, curKey,
									valueSound_NonLinear_Source[i++]);
						}
						continue;
					}

					if (curSectionName.equalsIgnoreCase(sectionNmaes[4])) {
						for (String curKey : keySound_NonLinear_Source_Market) {
							inif_aq.SetValue(curSectionName, curKey,
									valueSound_NonLinear_Source_Market[i++]);
						}
						continue;
					}

					if (curSectionName.equalsIgnoreCase(sectionNmaes[5])) {
						for (String curKey : keyVIRTUAL_SURROUND) {
							inif_aq.SetValue(curSectionName, curKey,
									valueVIRTUAL_SURROUND[i++]);
						}
						continue;
					}

					if (curSectionName.equalsIgnoreCase(sectionNmaes[6])) {
						for (String curKey : keyAVOutPathGain) {
							inif_aq.SetValue(curSectionName, curKey,
									valueAVOutPathGain[i++]);
						}
						continue;
					}
					
					if (curSectionName.equalsIgnoreCase(sectionNmaes[7])) {
						for (String curKey : keySPDIFOutPathGain) {
							inif_aq.SetValue(curSectionName, curKey,
									valueSPDIFOutPathGain[i++]);
						}
						continue;
					}

					if (curSectionName.equalsIgnoreCase(sectionNmaes[8])) {
						for (String curKey : keyLimiterThreshold) {
							inif_aq.SetValue(curSectionName, curKey,
									valueLimiterThreshold[i++]);
						}
						continue;
					}

					if (curSectionName.equalsIgnoreCase(sectionNmaes[9])) {
						for (String curKey : keyPEQ_PARAM) {
							inif_aq.SetValue(curSectionName, curKey,
									valuePEQ_PARAM[i++]);
						}
						continue;
					}

					if (curSectionName.equalsIgnoreCase(sectionNmaes[10])) {
						for (String curKey : keyAUDIO_NR_THR) {
							inif_aq.SetValue(curSectionName, curKey,
									valueAUDIO_NR_THR[i++]);
						}
						continue;
					}

				}

				if (!inif_aq.closeINI(OutAQinifilePath)) {
					return false;
				}

			}

			// =============

		} catch (Exception e) {

			e.printStackTrace();
			return false;

		}
		return true;
	}

	ArrayList<String> mDTSRows;
	private void readDTSInfo(String filePath) {
		// TODO Auto-generated method stub
		mDTSRows = new ArrayList<String>();
		mDTSRows.clear();
		String strLine;	
		BufferedReader br = null;
		try {
			br = new BufferedReader(new InputStreamReader(new FileInputStream(filePath) ,"UTF-8"));	
			while((strLine = br.readLine()) != null)
			{
				if(strLine.startsWith("[SRS_Tvol]")||strLine.startsWith("[SRS_Limiter]")||strLine.startsWith("[SRS_TruSurrond]"))
				{
					mDTSRows.add(strLine);
					//Toast.makeText(getApplicationContext(), strLine, Toast.LENGTH_LONG).show();
					break;
				}
			}
			while((strLine = br.readLine()) != null)
			{
				mDTSRows.add(strLine);
			}

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
		finally
		{
			if(br != null)
			{
				try {
					br.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}

	public boolean setFocusOrder() {

//		ButtonExportData.setNextFocusLeftId(R.id.ExportData);



		// inputgain
		seekBarPS_atv.setNextFocusRightId(R.id.seekBar_SP1);
//		seekBarPS_atv.setNextFocusUpId(0);
		seekBarPS_dtv.setNextFocusRightId(R.id.seekBar_SP2);
		seekBarPS_av.setNextFocusRightId(R.id.seekBar_SP3);
		seekBarPS_ypbpr.setNextFocusRightId(R.id.seekBar_SP4);
		seekBarPS_pc.setNextFocusRightId(R.id.seekBar_SP5);
		seekBarPS_hdmi.setNextFocusRightId(R.id.seekBar_SP6);
		seekBarPS_mm.setNextFocusRightId(R.id.seekBar_SP7);

		seekBarPS_atv.setNextFocusLeftId(R.id.seekBar_SP1);
		seekBarPS_dtv.setNextFocusLeftId(R.id.seekBar_SP2);
		seekBarPS_av.setNextFocusLeftId(R.id.seekBar_SP3);
		seekBarPS_ypbpr.setNextFocusLeftId(R.id.seekBar_SP4);
		seekBarPS_pc.setNextFocusLeftId(R.id.seekBar_SP5);
		seekBarPS_hdmi.setNextFocusLeftId(R.id.seekBar_SP6);
		seekBarPS_mm.setNextFocusLeftId(R.id.seekBar_SP7);





		// other
		edit_AQID.setNextFocusRightId(R.id.edit_version);
//		edit_AQID.setNextFocusUpId(1);
		edit_Version.setNextFocusRightId(R.id.edit_version);
		edit_Limiter.setNextFocusRightId(R.id.edit_limiterthreshold);
		edit_NRThreshold.setNextFocusRightId(R.id.edit_nrthreshold);

		edit_AQID.setNextFocusLeftId(R.id.edit_aqid);
		edit_Version.setNextFocusLeftId(R.id.edit_aqid);
		edit_Limiter.setNextFocusLeftId(R.id.switch3);
		edit_NRThreshold.setNextFocusLeftId(R.id.edit_nrthreshold);
		
		switch_Limiter.setNextFocusLeftId(R.id.switch3);
		switch_Limiter.setNextFocusRightId(R.id.edit_limiterthreshold);
		
		
		switch_PEQ.setNextFocusLeftId(R.id.switch1);
		switch_PEQ.setNextFocusRightId(R.id.switch1);

		edit_PEQBand_1.setNextFocusLeftId(R.id.edit_peq_band1);
		edit_PEQBand_3.setNextFocusRightId(R.id.edit_peq_band3);
		edit_PEQFrequenceH_1.setNextFocusLeftId(R.id.edit_peq_freq_h1);
		edit_PEQFrequenceH_1.setNextFocusRightId(R.id.edit_peq_freq_l1);
		edit_PEQFrequenceL_1.setNextFocusLeftId(R.id.edit_peq_freq_h1);
		edit_PEQFrequenceL_1.setNextFocusRightId(R.id.edit_peq_freq_l1);
		edit_EQ_Value_1.setNextFocusLeftId(R.id.edit_peq_eqvalue1);
		edit_EQ_Value_1.setNextFocusRightId(R.id.edit_peq_eqgain1);
		edit_PEQGain_1.setNextFocusLeftId(R.id.edit_peq_eqvalue1);
		edit_PEQGain_1.setNextFocusRightId(R.id.edit_peq_eqgain1);
		
		switch_GEQ.setNextFocusLeftId(R.id.switch4);
		switch_GEQ.setNextFocusRightId(R.id.switch4); 
		edit_GEQ1.setNextFocusLeftId(R.id.edit_geq1);
		edit_GEQ1.setNextFocusRightId(R.id.edit_geq2); 
		edit_GEQ2.setNextFocusLeftId(R.id.edit_geq1);
		edit_GEQ2.setNextFocusRightId(R.id.edit_geq3); 
		edit_GEQ3.setNextFocusLeftId(R.id.edit_geq2);
		edit_GEQ3.setNextFocusRightId(R.id.edit_geq3); 
		edit_GEQ4.setNextFocusLeftId(R.id.edit_geq4);
		edit_GEQ4.setNextFocusRightId(R.id.edit_geq5); 
		edit_GEQ5.setNextFocusLeftId(R.id.edit_geq4);
		edit_GEQ5.setNextFocusRightId(R.id.edit_geq5); 

		return true;
	}

	// ==========================================amp================================================
	//shougang.lin add modify 2014.07.02 next 2 line
   // DeviceManager mDeviceManager = DeviceManager.getInstance();
   // ArrayList<MountPoint> deviceLabel = mDeviceManager.getMountPointList();    
	
	public String SDPath = null;	
	public static final String LocalPath = "/hwcfg/aq/";
	public String srcFilePath = "null";
	public String OutfilePath = null;
//	public String OutAmpfileBootPath = null;
	public String OutLocalFilePath = null;
	public String HighOutfilePath = null;
	public String LowOutfilePath = null;
	public String HighOutLocalFilePath = null;
	public String LowOutLocalFilePath = null;
	public String OutAQinifilePath = null;
	public String OutAQinifileSDCardPath = null;
	public String OutMICinifilePath = null;
	public String OutMICinifileSDCardPath = null;
	static final String cmd = "su -root";
	public String[] filePath = new String[] { " ", " ", " " };
	public List<String> listfilePath;

	static final public String[] Amptype = new String[] { "5711", "5707","5719" };
	static final public String[] HighLowType = new String[] { "Treble(MAIN)",
			"Bass(SUB)" };
	public int AmpIndex = 0;
	public int HighLowIndex = 0;
	public boolean bothAmp = false;
	public boolean both5711 = false;
	public boolean both5719 = false;
	String CurProductName = "UnknowProduct";


	public void initAMP() {


		// Export Data Button
		ButtonExportData = (Button) mTabHost_aq.findViewById(R.id.ExportAQData);
		ButtonExportData.setOnClickListener(OutputResult);
		ButtonExportData.setOnFocusChangeListener(new OnFocusChangeListener() {

			@Override
			public void onFocusChange(View v, boolean isFocus) {
				// TODO Auto-generated method stub
				if (isFocus) {
					if (!switchFocus) {
						focusEditText.requestFocus();
					}
				}
			}

		});
	}




	public String ParseCFGData(String Src) {
		int i = 0;
		int j = 0;
		String strRet = "";

		String[] strTemp = null;
		String[] strLine = null;
		String[] strSpace = null;
		String Sub;
		String str;
		strTemp = Src.split("\n");
		
		//5719  cfg the last line, one VALUE, one space patch
		if(2==AmpIndex)
		{
			Sub=strTemp[strTemp.length-1];
			
			Log.v("SUB", Sub);
			strLine=Sub.split("  ");
			str = Integer.toHexString(strLine.length);
			Log.v("SUB1", str);
			strSpace=Sub.split(" ");
			str = Integer.toHexString(strSpace.length);
			Log.v("SUB2", str);	
			
			if((strSpace.length>=3)&&(strLine.length<2))
			{
				OpenTipDialog(getString(R.string.pq_error),getString(R.string.aq_space_error));
				ResultInfoDialog resultDialog = new ResultInfoDialog(
						AQService.this, "Please add a space to the last line of the CFG file in the 5719 power amplifier£¬Otherwise, the data error is exported£¡£¡£¡");
				resultDialog.show();
			}	
			
		}	

		while (i < strTemp.length) {
			if (strTemp[i].startsWith("! ", 0))// The exclamation mark begins with a comment line and skips
				strRet += "";
			else if (strTemp[i].startsWith("X", 0)) {// X the beginning is the data line
				Sub = strTemp[i].substring(1);// Gets the substring (not including X) behind the row X

				strLine = Sub.split("  ");// Get a single value (each line of data is numeric, with two spaces, so here's the address, the space, and the first value in the strLine[0])
				str = Integer.toHexString(strLine.length);// The number of rows is converted to 16 hexadecimal string
				Sub = str;
				for (j = 0; j < strLine.length; j++)
					// Process each value one by one
					Sub = Sub + " " + strLine[j];// The number is followed by each value separated by spaces

				Log.v(TAG, Sub);
				strRet += Sub.trim() + " ";

			}
			i++;

		}

		Log.v(TAG, strRet);

		return strRet.trim() + " 00";
	}

	/*
	 * public boolean CheckSDCardSwitchOn() { if
	 * (Environment.getExternalStorageState().equals(
	 * Environment.MEDIA_MOUNTED)) { return true; } else { return false; } }
	 */

	/*
	 * public void OpenTipDialog(String strTitle, String strInfo) { new
	 * AlertDialog.Builder(this).setTitle(strTitle).setMessage(strInfo)
	 * .setIcon(android.R.drawable.ic_dialog_info) // .setView(new
	 * EditText(this)) .setPositiveButton("Confirm;", null) //
	 * .setNegativeButton("no",null) .show(); }
	 */







	/*
	 * public void openOptionsDialog() { new
	 * AlertDialog.Builder(this).setTitle("file name")
	 * .setMessage("Please enter the export power amplifier file name:(*.bin)")
	 * .setIcon(android.R.drawable.ic_dialog_info) .setView(new
	 * EditText(this)).setPositiveButton("Confirm", null) .setNegativeButton("no",
	 * null).show(); }
	 */

	// ============================================================================================================
	// =========================================== Global common function
	// =========================================
	// ============================================================================================================
	String tabName[] = { "Digital power amplifier       ", "AQ configuration         ", "Microphone          " };
	// button ExportData's listener
	private OnClickListener OutputResult = new OnClickListener() {
		public void onClick(View v) {
			int Ret[] = { 0, 0, 0 };
			String RetInfo = "";
			
			Ret[0] = 0;//produceAmpBinFile();
//			Ret[1] = produceAQIniFile();
			Log.d(TAG, "Start save ini");
//			saveChangeEQProgress(SOUND_MODE_ID, 0, seekBarBand1.getProgress());
//			saveChangeEQProgress(SOUND_MODE_ID, 1, seekBarBand2.getProgress());
//			saveChangeEQProgress(SOUND_MODE_ID, 2, seekBarBand3.getProgress());
//			saveChangeEQProgress(SOUND_MODE_ID, 3, seekBarBand4.getProgress());
//			saveChangeEQProgress(SOUND_MODE_ID, 4, seekBarBand5.getProgress());
			AudioInputSource curAudioSource = MtkTvFApiAudio.getInstance().getCurrentAudioSrc();
//			saveChangePreScalerProgress(0, seekBarPS_atv.getProgress());
//			saveChangePreScalerProgress(1, seekBarPS_dtv.getProgress());
//			saveChangePreScalerProgress(2, seekBarPS_av.getProgress());
//			saveChangePreScalerProgress(5, seekBarPS_hdmi.getProgress());
//			saveChangePreScalerProgress(6, seekBarPS_mm.getProgress());
			int ret = -1;
			if(SDPath == null || SDPath.isEmpty()) {
	    		Toast.makeText(AQService.this, "U disk not found!!!", Toast.LENGTH_LONG).show();
	    	}else {
				String AQExportPath = SDPath + "/aq_export";
	    		if(!MtkTvFApiSystem.getInstance().isFolderExist(AQExportPath)) {
	    			MtkTvFApiSystem.getInstance().createFolder(AQExportPath);
	    		}
				for(int i = 0; i < outinputAQFile.length; i++){
//					String srcFile = "/vendor/cusdata/bsp/chip/aq/InputSrc/"+outinputAQFile[i];
					String srcFile = Contants.FACTORY_TVTOOLS_INPUTSOURCEPATH + outinputAQFile[i];
					String dstPath = SDPath +"/aq_export/"+outinputAQFile[i];
					ret = MtkTvFApiSystem.getInstance().copyFile(srcFile, dstPath, false);
					Log.d(TAG,"copyFile "+ret);
					if(ret != 0){
						break;
					}
				}
				for(int j = 0; j < outmodeAQFile.length; j++){
//					String srcFile = "/vendor/cusdata/bsp/chip/aq/SoundStyle/"+outmodeAQFile[j];
					String srcFile = Contants.FACTORY_TVTOOLS_SOUNDSTYLEPATH + outmodeAQFile[j];
					String dstPath = SDPath +"/aq_export/"+outmodeAQFile[j];
					ret = MtkTvFApiSystem.getInstance().copyFile(srcFile, dstPath, false);
					Log.d(TAG,"copyFile "+ret);
					if(ret != 0){
						break;
					}
				}
			}

	        
	        ret = MtkTvFApiAudio.getInstance().saveAudioIni();
			Log.d(TAG, "saveAudioIni " + ret );
			int peqEnable = MtkTvFApiAudio.getInstance().getPEQEnable(EnumSoundMode.values()[SOUND_MODE_ID],(short)0);
			if(peqEnable == 1){
				SoundEffectParams argSoundEffect = new SoundEffectParams();
				MtkTvFApiAudio.getInstance().getAudioIniBasicSndParams(EnumSoundMode.values()[SOUND_MODE_ID],argSoundEffect);
				argSoundEffect.PeqBandNum = 13;
				argSoundEffect.geqBandNum = 5;
				argSoundEffect.aPeqFrequecny[0] = PEQ1[1]*100+PEQ1[2];
				argSoundEffect.aPeqFrequecny[1] = PEQ2[1]*100+PEQ2[2];
				argSoundEffect.aPeqFrequecny[2] = PEQ3[1]*100+PEQ3[2];
				argSoundEffect.aPeqQ[0] = PEQ1[3];
				argSoundEffect.aPeqQ[1] = PEQ2[3];
				argSoundEffect.aPeqQ[2] = PEQ3[3];
				argSoundEffect.aPeqGain[0] = PEQ1[4];
				argSoundEffect.aPeqGain[1] = PEQ2[4];
				argSoundEffect.aPeqGain[2] = PEQ3[4];
						
				ret = MtkTvFApiAudio.getInstance().setBasicSoundEffect(EnumSoundMode.values()[SOUND_MODE_ID],EnumBasicSoundType.E_FAPI_AUD_BASIC_SND_PEQ, argSoundEffect);
				Log.d(TAG, "setBasicSoundEffect " + ret );
			}
			String DTVFile = "/vendor/cusdata/bsp/chip/aq/InputSrc/BasicSound_DTV.ini";
			String ATVFile = "/vendor/cusdata/bsp/chip/aq/InputSrc/BasicSound_ATV.ini";
			String HDMIFile = "/vendor/cusdata/bsp/chip/aq/InputSrc/BasicSound_HDMI.ini";
			String MMFile = "/vendor/cusdata/bsp/chip/aq/InputSrc/BasicSound_MM.ini";
			String CVBSFile = "/vendor/cusdata/bsp/chip/aq/InputSrc/BasicSound_CVBS.ini";
			String DefaultFile = "/vendor/cusdata/bsp/chip/aq/InputSrc/BasicSound_Default.ini";

			ret = MtkTvFApiAudio.getInstance().loadAqParamFromIni(ATVFile);
			ret = MtkTvFApiAudio.getInstance().loadAqParamFromIni(HDMIFile);
			ret = MtkTvFApiAudio.getInstance().loadAqParamFromIni(MMFile);
			ret = MtkTvFApiAudio.getInstance().loadAqParamFromIni(CVBSFile);
			ret = MtkTvFApiAudio.getInstance().loadAqParamFromIni(DefaultFile);
			ret = MtkTvFApiAudio.getInstance().loadAqParamFromIni(DTVFile);
//			ret = MtkTvFApiAudio.getInstance().setVolumeCurve(volumeTblPath, AudioInputSource.DTV, EnumAoutPath.E_FAPI_AUD_PATH_MAIN_SPEAKER);
//	        Log.d(TAG,"SaveVolumeCure "+ret+" volumeTblPath "+volumeTblPath);
	        
//			if(AQ_MIC_OFF){
//				Ret[2] = 0;
//				for (int i = 1; i < 2; i++) {
//					RetInfo += tabName[i] + "[" + getErrorResultInfo(i, Ret[i])
//							+ "]" + "\n\n";
//				}				
//			}else {
//				Ret[2] = produceMicIniFile();
//				for (int i = 1; i < 3; i++) {
//					RetInfo += tabName[i] + "[" + getErrorResultInfo(i, Ret[i])
//							+ "]" + "\n\n";
//				}				
//			}						
//						
//			try {
//				Runtime.getRuntime().exec("sync");
//				Runtime.getRuntime().exec("sync");
//			} catch (IOException e) {
//				// TODO Auto-generated catch block
//				OpenTipDialog("sync wrong", "文件同步失败，U盘文件可能没有正确生成，请手动sync");
//			}
			// OpenTipDialog("File generation information:", RetInfo);
//			MtkTvFApiAudio.getInstance().setCurrentAudioSrc(curAudioSource);
			setCurrentAudioSrcByinputsource();
			RetInfo = (ret == 0)?getString(R.string.pq_save_successs):getString(R.string.pq_failed);
			ResultInfoDialog resultDialog = new ResultInfoDialog(
					AQService.this, RetInfo);
			resultDialog.show();

		}
	};



	public int produceAQIniFile() {
		int i;
		INIFile inif_aq = new INIFile("AQ_aq", CurProductName);
		// inif_aq.openINI(OutAQinifilePath);

		File file_aq_ini = new File(OutAQinifilePath);
		File SDfile_aq_ini = new File(OutAQinifileSDCardPath);

		try {
			file_aq_ini.createNewFile();

			for (String curSectionName : sectionNmaes) {
				i = 0;

				if (curSectionName.equalsIgnoreCase(sectionNmaes[0])) {
					for (String curKey : keyIniVersion) {
						inif_aq.SetValue(curSectionName, curKey,
								valueIniVersion[i++]);
					}
					continue;
				}

				if (curSectionName.equalsIgnoreCase(sectionNmaes[1])) {
					for (String curKey : keySourceSpeakerPrescaler) {
						inif_aq.SetValue(curSectionName, curKey,
								valueSourceSpeakerPrescaler[i++]);
					}
					continue;
				}

				if (curSectionName.equalsIgnoreCase(sectionNmaes[2])) {
					for (String curKey : keySoundModeSetting) {
						inif_aq.SetValue(curSectionName, curKey,
								valueSoundModeSetting[i++]);
					}
					continue;
				}

				if (curSectionName.equalsIgnoreCase(sectionNmaes[3])) {
					for (String curKey : keySound_NonLinear_Source) {
						inif_aq.SetValue(curSectionName, curKey,
								valueSound_NonLinear_Source[i++]);
					}
					continue;
				}

				if (curSectionName.equalsIgnoreCase(sectionNmaes[4])) {
					for (String curKey : keySound_NonLinear_Source_Market) {
						inif_aq.SetValue(curSectionName, curKey,
								valueSound_NonLinear_Source_Market[i++]);
					}
					continue;
				}

				if (curSectionName.equalsIgnoreCase(sectionNmaes[5])) {
					for (String curKey : keyVIRTUAL_SURROUND) {
						inif_aq.SetValue(curSectionName, curKey,
								valueVIRTUAL_SURROUND[i++]);
					}
					continue;
				}

				if (curSectionName.equalsIgnoreCase(sectionNmaes[6])) {
					for (String curKey : keyAVOutPathGain) {
						inif_aq.SetValue(curSectionName, curKey,
								valueAVOutPathGain[i++]);
					}
					continue;
				}
				
				if (curSectionName.equalsIgnoreCase(sectionNmaes[7])) {
					for (String curKey : keySPDIFOutPathGain) {
						inif_aq.SetValue(curSectionName, curKey,
								valueSPDIFOutPathGain[i++]);
					}
					continue;
				}


				if (curSectionName.equalsIgnoreCase(sectionNmaes[8])) {
					for (String curKey : keyLimiterThreshold) {
						inif_aq.SetValue(curSectionName, curKey,
								valueLimiterThreshold[i++]);
					}
					continue;
				}

				if (curSectionName.equalsIgnoreCase(sectionNmaes[9])) {
					for (String curKey : keyPEQ_PARAM) {
						inif_aq.SetValue(curSectionName, curKey,
								valuePEQ_PARAM[i++]);
					}
					continue;
				}

				if (curSectionName.equalsIgnoreCase(sectionNmaes[10])) {
					for (String curKey : keyAUDIO_NR_THR) {
						inif_aq.SetValue(curSectionName, curKey,
								valueAUDIO_NR_THR[i++]);
					}
					continue;
				}

			}

			inif_aq.closeINI(OutAQinifilePath);


			//writeDTSInfo(OutAQinifilePath);
		    if(CheckSDCardSwitchOn()){	
				if (!fileCopy(file_aq_ini, SDfile_aq_ini, true)) {
					return 1;
				}
		    }

		} catch (Exception e) {
			e.printStackTrace();
			return 2;
		}

		return 0;
	}


	
	private void writeDTSInfo(String filePath) {
		// TODO Auto-generated method stub
		readAQInfo(filePath);
		
		PrintWriter printWriter = null;
		try 
		{
			printWriter = new PrintWriter(new OutputStreamWriter(new FileOutputStream(filePath),"UTF-8"));
			for(String strLine : mAQRows)
			{
				printWriter.print(strLine + "\r\n");				
			}
			for(String strLine : mDTSRows)
			{
				printWriter.print(strLine + "\r\n");	
			}
		} 
		catch (Exception e)
		{
			e.printStackTrace();
		}
		finally
		{
			if(printWriter != null)
			{
				printWriter.close();
			}
		}
	}
	
	ArrayList<String> mAQRows;
	private void readAQInfo(String filePath)
	{
		mAQRows = new ArrayList<String>();
		mAQRows.clear();
		String strLine;	
		BufferedReader br = null;
		try {
			br = new BufferedReader(new InputStreamReader(new FileInputStream(filePath) ,"UTF-8"));	
			while((strLine = br.readLine()) != null)
			{
				mAQRows.add(strLine);
				if(strLine.startsWith("[SRS_Tvol]")||strLine.startsWith("[SRS_Limiter]")||strLine.startsWith("[SRS_TruSurrond]"))
				{				
					break;
				}
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
		finally
		{
			if(br != null)
			{
				try {
					br.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
	public boolean fileCopy(File srcfile, File desfile, boolean reWrite) {
		if (!srcfile.exists() || !srcfile.isFile() || !srcfile.canRead()) {
			return false;
		}

		if (!desfile.getParentFile().exists()) {
			return false;
		}

		if (desfile.exists() && reWrite) {
			desfile.delete();
		}

		try {
			FileInputStream srcStream = new FileInputStream(srcfile);
			FileOutputStream desStream = new FileOutputStream(desfile);
			int count;
			byte buffer[] = new byte[1024];

			try {
				while ((count = srcStream.read(buffer)) > 0) {
					desStream.write(buffer, 0, count);
				}

				srcStream.close();
				desStream.close();

			} catch (IOException e) {

				e.printStackTrace();
				return false;

			}

		} catch (FileNotFoundException e) {

			e.printStackTrace();
			return false;

		}

		return true;
	}



	public String getErrorResultInfo(int type, int error_ID) {
		// if(error_ID==0)
		// return "OK!";

		String strRet = "Error ";
		if (type == 0) {
			switch (error_ID) {
			case 0:
				if (both5711) {
					if (0 == HighLowIndex) {
						strRet = "OK!  " + CurProductName + "_5711_H.bin";
					} else {
						strRet = "OK!  " + CurProductName + "_5711_L.bin";
					}
				} else if(both5719){
					if (0 == HighLowIndex) {
						strRet = "OK!  " + CurProductName + "_5719_H.bin";
					} else {
						strRet = "OK!  " + CurProductName + "_5719_L.bin";
					}
				}else {
					strRet = "OK!  " + CurProductName + "_" + Amptype[AmpIndex]
							+ ".bin";
				}

				break;
			case 1:
				strRet += "the U disk was not detected!";
				break;
			case 2:
				strRet += "the source file path is empty!";
				break;
			case 3:
				strRet += "data conversion error!";
				break;
			case 4:
				strRet += "file creation error!";
				break;
			default:
				break;
			}
		}

		if (type == 1) {
			switch (error_ID) {
			case 0:
				strRet = "OK!  " + CurProductName + "_aq.ini";
				break;
			case 1:
				strRet += getString(R.string.aq_file_copy_error);
				break;
			case 2:
				strRet += "file creation error!";
				break;

			default:
				break;
			}
		}

		if (type == 2) {
			switch (error_ID) {
			case 0:
				if(AQ_MIC_OFF){
					strRet = "";
				}else{
					strRet = "OK!  " + CurProductName + "_mic.ini";
				}				
				break;
			case 1:
				strRet += getString(R.string.aq_file_copy_error);
				break;
			case 2:
				strRet += "file creation error!";
				break;
			default:
				break;

			}
		}

		return strRet;
	}

	// ============================================================================================================
	// ==================================Nonlinearr================================================================
	// ============================================================================================================

	
	
	// ============================================================================================================
	// ==================================PreScaler================================================================
	// ============================================================================================================
	SeekBar seekBarPS_atv, seekBarPS_dtv, seekBarPS_av, seekBarPS_ypbpr,
			seekBarPS_pc, seekBarPS_hdmi, seekBarPS_mm, seekBarPS_net;
	TextView valueTextPS_atv, valueTextPS_dtv, valueTextPS_av,
			valueTextPS_ypbpr, valueTextPS_pc, valueTextPS_hdmi,
			valueTextPS_mm, valueTextPS_net;
	EditText edittext_pre_limiterthreshold;
	

	public void initPrescaler() {
		getAllValuesAboutPrescaler();
		findViewsByIdAndInitTheirAppearanceOnPrescaler();
		applyAllValuesToViewsOnPrescaler();
		addListenerToEveryViewOnPrescaler();

//		saveChangePreScalerProgress(SRC_ID, Integer.parseInt(
//				valueSourceSpeakerPrescaler[SRC_ID]
//						.replaceFirst("0x(.*)", "$1"), 16));

	}

	private void addListenerToEveryViewOnPrescaler() {
		// TODO Auto-generated method stub
		seekBarPS_atv.setOnSeekBarChangeListener(SeekBarListener_PSatv);
		seekBarPS_dtv.setOnSeekBarChangeListener(SeekBarListener_PSdtv);
		seekBarPS_av.setOnSeekBarChangeListener(SeekBarListener_PSav);
		seekBarPS_ypbpr.setOnSeekBarChangeListener(SeekBarListener_PSypbpr);
		seekBarPS_pc.setOnSeekBarChangeListener(SeekBarListener_PSpc);
		seekBarPS_hdmi.setOnSeekBarChangeListener(SeekBarListener_PShdmi);
		seekBarPS_mm.setOnSeekBarChangeListener(SeekBarListener_PSmm);
		seekBarPS_net.setOnSeekBarChangeListener(SeekBarListener_PSnet);
		
		edittext_pre_limiterthreshold.setOnFocusChangeListener(focusChangeListener_Limiter);
		edittext_pre_limiterthreshold.setOnKeyListener(keyListener_Limiter);
	}

	public OnSeekBarChangeListener SeekBarListener_PSatv = new OnSeekBarChangeListener() {
		public void onProgressChanged(SeekBar seekBar, int progress,
				boolean fromUser) {

//			String strTemp = Integer.toString(progress  - 10);
			valueTextPS_atv.setText(((double)(progress  - 80))/8+"");
			saveChangePreScalerProgress(0, progress);
			Log.v(TAG, "current band value:" + ((double)(progress  - 80))/8+"");
		}

		public void onStartTrackingTouch(SeekBar seekBar) {
			Log.v(TAG, "start Tracking");
		}

		public void onStopTrackingTouch(SeekBar seekBar) {
			Log.v(TAG, "stop Tracking");
		}

	};

	public OnSeekBarChangeListener SeekBarListener_PSdtv = new OnSeekBarChangeListener() {
		public void onProgressChanged(SeekBar seekBar, int progress,
				boolean fromUser) {
//			String strTemp = Integer.toString(progress  - 80);
			valueTextPS_dtv.setText(((double)(progress  - 80))/8+"");
			saveChangePreScalerProgress(1, progress);
		}

		public void onStartTrackingTouch(SeekBar seekBar) {
		}

		public void onStopTrackingTouch(SeekBar seekBar) {
		}

	};

	public OnSeekBarChangeListener SeekBarListener_PSav = new OnSeekBarChangeListener() {
		public void onProgressChanged(SeekBar seekBar, int progress,
				boolean fromUser) {
//			String strTemp = Integer.toString(progress  - 10);
			valueTextPS_av.setText(((double)(progress  - 80))/8+"");
			saveChangePreScalerProgress(2, progress);
		}

		public void onStartTrackingTouch(SeekBar seekBar) {
		}

		public void onStopTrackingTouch(SeekBar seekBar) {
		}

	};

	public OnSeekBarChangeListener SeekBarListener_PSypbpr = new OnSeekBarChangeListener() {
		public void onProgressChanged(SeekBar seekBar, int progress,
				boolean fromUser) {
//			String strTemp = Integer.toString(progress  - 10);
			valueTextPS_ypbpr.setText(((double)(progress  - 80))/8+"");
			saveChangePreScalerProgress(3, progress);
		}

		public void onStartTrackingTouch(SeekBar seekBar) {
		}

		public void onStopTrackingTouch(SeekBar seekBar) {
		}

	};

	public OnSeekBarChangeListener SeekBarListener_PSpc = new OnSeekBarChangeListener() {
		public void onProgressChanged(SeekBar seekBar, int progress,
				boolean fromUser) {
//			String strTemp = Integer.toString(progress  - 10);
			valueTextPS_pc.setText(((double)(progress  - 80))/8+"");
			saveChangePreScalerProgress(4, progress);
		}

		public void onStartTrackingTouch(SeekBar seekBar) {
		}

		public void onStopTrackingTouch(SeekBar seekBar) {
		}

	};

	public OnSeekBarChangeListener SeekBarListener_PShdmi = new OnSeekBarChangeListener() {
		public void onProgressChanged(SeekBar seekBar, int progress,
				boolean fromUser) {
//			String strTemp = Integer.toString(progress  - 10);
			valueTextPS_hdmi.setText(((double)(progress  - 80))/8+"");
			saveChangePreScalerProgress(5, progress);
		}

		public void onStartTrackingTouch(SeekBar seekBar) {
		}

		public void onStopTrackingTouch(SeekBar seekBar) {
		}

	};
	public OnSeekBarChangeListener SeekBarListener_PSmm = new OnSeekBarChangeListener() {
		public void onProgressChanged(SeekBar seekBar, int progress,
				boolean fromUser) {
//			String strTemp = Integer.toString(progress - 10);
			valueTextPS_mm.setText(((double)(progress  - 80))/8+"");
			saveChangePreScalerProgress(6, progress);
		}

		public void onStartTrackingTouch(SeekBar seekBar) {
		}

		public void onStopTrackingTouch(SeekBar seekBar) {
		}

	};

	public OnSeekBarChangeListener SeekBarListener_PSnet = new OnSeekBarChangeListener() {
		public void onProgressChanged(SeekBar seekBar, int progress,
				boolean fromUser) {
//			String strTemp = Integer.toString(progress - 10);
			valueTextPS_net.setText(((double)(progress  - 80))/8+"");
			saveChangePreScalerProgress(7, progress);
		}

		public void onStartTrackingTouch(SeekBar seekBar) {
		}

		public void onStopTrackingTouch(SeekBar seekBar) {
		}

	};
	
	public OnSeekBarChangeListener SeekBarListener_PEQGain_band1 = new OnSeekBarChangeListener() {
		public void onProgressChanged(SeekBar seekBar, int progress,
				boolean fromUser) {
			saveChangePeqGainrProgress(0, progress);
			TextView_peqgain_band1.setText(progress*5+"");
		}

		public void onStartTrackingTouch(SeekBar seekBar) {
			Log.v(TAG, "start Tracking");
		}

		public void onStopTrackingTouch(SeekBar seekBar) {
			Log.v(TAG, "stop Tracking");
		}

	};
	public OnSeekBarChangeListener SeekBarListener_PEQGain_band2 = new OnSeekBarChangeListener() {
		public void onProgressChanged(SeekBar seekBar, int progress,
				boolean fromUser) {
			saveChangePeqGainrProgress(1, progress);
			TextView_peqgain_band2.setText(progress*5+"");
		}

		public void onStartTrackingTouch(SeekBar seekBar) {
			Log.v(TAG, "start Tracking");
		}

		public void onStopTrackingTouch(SeekBar seekBar) {
			Log.v(TAG, "stop Tracking");
		}

	};
	public OnSeekBarChangeListener SeekBarListener_PEQGain_band3 = new OnSeekBarChangeListener() {
		public void onProgressChanged(SeekBar seekBar, int progress,
				boolean fromUser) {
			saveChangePeqGainrProgress(2, progress);
			TextView_peqgain_band3.setText(progress*5+"");
		}

		public void onStartTrackingTouch(SeekBar seekBar) {
			Log.v(TAG, "start Tracking");
		}

		public void onStopTrackingTouch(SeekBar seekBar) {
			Log.v(TAG, "stop Tracking");
		}

	};
	public OnSeekBarChangeListener SeekBarListener_PEQGain_band4 = new OnSeekBarChangeListener() {
		public void onProgressChanged(SeekBar seekBar, int progress,
				boolean fromUser) {
			saveChangePeqGainrProgress(3, progress);
			TextView_peqgain_band4.setText(progress*5+"");
		}

		public void onStartTrackingTouch(SeekBar seekBar) {
			Log.v(TAG, "start Tracking");
		}

		public void onStopTrackingTouch(SeekBar seekBar) {
			Log.v(TAG, "stop Tracking");
		}

	};
	public OnSeekBarChangeListener SeekBarListener_PEQGain_band5 = new OnSeekBarChangeListener() {
		public void onProgressChanged(SeekBar seekBar, int progress,
				boolean fromUser) {
			saveChangePeqGainrProgress(4, progress);
			TextView_peqgain_band5.setText(progress*5+"");
		}

		public void onStartTrackingTouch(SeekBar seekBar) {
			Log.v(TAG, "start Tracking");
		}

		public void onStopTrackingTouch(SeekBar seekBar) {
			Log.v(TAG, "stop Tracking");
		}

	};
	public OnSeekBarChangeListener SeekBarListener_PEQGain_band6 = new OnSeekBarChangeListener() {
		public void onProgressChanged(SeekBar seekBar, int progress,
				boolean fromUser) {
			saveChangePeqGainrProgress(5, progress);
			TextView_peqgain_band6.setText(progress*5+"");
		}

		public void onStartTrackingTouch(SeekBar seekBar) {
			Log.v(TAG, "start Tracking");
		}

		public void onStopTrackingTouch(SeekBar seekBar) {
			Log.v(TAG, "stop Tracking");
		}

	};
	public OnSeekBarChangeListener SeekBarListener_PEQGain_band7 = new OnSeekBarChangeListener() {
		public void onProgressChanged(SeekBar seekBar, int progress,
				boolean fromUser) {
			saveChangePeqGainrProgress(6, progress);
			TextView_peqgain_band7.setText(progress*5+"");
		}

		public void onStartTrackingTouch(SeekBar seekBar) {
			Log.v(TAG, "start Tracking");
		}

		public void onStopTrackingTouch(SeekBar seekBar) {
			Log.v(TAG, "stop Tracking");
		}

	};
	public OnSeekBarChangeListener SeekBarListener_PEQGain_band8 = new OnSeekBarChangeListener() {
		public void onProgressChanged(SeekBar seekBar, int progress,
				boolean fromUser) {
			saveChangePeqGainrProgress(7, progress);
			TextView_peqgain_band8.setText(progress*5+"");
		}

		public void onStartTrackingTouch(SeekBar seekBar) {
			Log.v(TAG, "start Tracking");
		}

		public void onStopTrackingTouch(SeekBar seekBar) {
			Log.v(TAG, "stop Tracking");
		}

	};
	public OnSeekBarChangeListener SeekBarListener_PEQGain_band9 = new OnSeekBarChangeListener() {
		public void onProgressChanged(SeekBar seekBar, int progress,
				boolean fromUser) {
			saveChangePeqGainrProgress(8, progress);
			TextView_peqgain_band9.setText(progress*5+"");
		}

		public void onStartTrackingTouch(SeekBar seekBar) {
			Log.v(TAG, "start Tracking");
		}

		public void onStopTrackingTouch(SeekBar seekBar) {
			Log.v(TAG, "stop Tracking");
		}

	};
	public OnSeekBarChangeListener SeekBarListener_PEQGain_band10 = new OnSeekBarChangeListener() {
		public void onProgressChanged(SeekBar seekBar, int progress,
				boolean fromUser) {
			saveChangePeqGainrProgress(9, progress);
			TextView_peqgain_band10.setText(progress*5+"");
		}

		public void onStartTrackingTouch(SeekBar seekBar) {
			Log.v(TAG, "start Tracking");
		}

		public void onStopTrackingTouch(SeekBar seekBar) {
			Log.v(TAG, "stop Tracking");
		}

	};
	public OnSeekBarChangeListener SeekBarListener_PEQGain_band11 = new OnSeekBarChangeListener() {
		public void onProgressChanged(SeekBar seekBar, int progress,
				boolean fromUser) {
			saveChangePeqGainrProgress(10, progress);
			TextView_peqgain_band11.setText(progress*5+"");
		}

		public void onStartTrackingTouch(SeekBar seekBar) {
			Log.v(TAG, "start Tracking");
		}

		public void onStopTrackingTouch(SeekBar seekBar) {
			Log.v(TAG, "stop Tracking");
		}

	};
	public OnSeekBarChangeListener SeekBarListener_PEQGain_band12 = new OnSeekBarChangeListener() {
		public void onProgressChanged(SeekBar seekBar, int progress,
				boolean fromUser) {
			saveChangePeqGainrProgress(11, progress);
			TextView_peqgain_band12.setText(progress*5+"");
		}

		public void onStartTrackingTouch(SeekBar seekBar) {
			Log.v(TAG, "start Tracking");
		}

		public void onStopTrackingTouch(SeekBar seekBar) {
			Log.v(TAG, "stop Tracking");
		}

	};
	public OnSeekBarChangeListener SeekBarListener_PEQGain_band13 = new OnSeekBarChangeListener() {
		public void onProgressChanged(SeekBar seekBar, int progress,
				boolean fromUser) {
			saveChangePeqGainrProgress(12, progress);
			TextView_peqgain_band13.setText(progress*5+"");
		}

		public void onStartTrackingTouch(SeekBar seekBar) {
			Log.v(TAG, "start Tracking");
		}

		public void onStopTrackingTouch(SeekBar seekBar) {
			Log.v(TAG, "stop Tracking");
		}

	};
	private void saveChangePeqGainrProgress(int band, int progress) {
		MtkTvFApiAudio.getInstance().setPeqGain(EnumSoundMode.values()[SOUND_MODE_ID],(short)band, (short)(progress*5));
	}
	

	private void applyAllValuesToViewsOnPrescaler() {
		// TODO Auto-generated method stub
		getSoundMode();
		
//		for(int i = 0; i < valueSourceSpeakerPrescaler.length; i++){
//			valueSourceSpeakerPrescaler[i] = preScale+"";
//		}
		AudioInputSource curAudioSource = MtkTvFApiAudio.getInstance().getCurrentAudioSrc();
		MtkTvFApiAudio.getInstance().setCurrentAudioSrc(AudioInputSource.ATV);
		double preScale = MtkTvFApiAudio.getInstance().getPrescale(EnumSoundMode.values()[SOUND_MODE_ID] ,EnumAudOutputType.SPEAKER);
		seekBarPS_atv
				.setProgress((int)(((preScale + 10))*8));
//						.replaceFirst("0x(.*)", "$1"), 16));
		valueTextPS_atv
				.setText(preScale+"");
//						valueSourceSpeakerPrescaler[0].replaceFirst("0x(.*)",
//								"$1"), 16)));
		// setvalue

		MtkTvFApiAudio.getInstance().setCurrentAudioSrc(AudioInputSource.DTV);
		preScale = MtkTvFApiAudio.getInstance().getPrescale(EnumSoundMode.values()[SOUND_MODE_ID] ,EnumAudOutputType.SPEAKER);
		seekBarPS_dtv
				.setProgress((int)(((preScale + 10))*8));
//						.replaceFirst("0x(.*)", "$1"), 16));
		valueTextPS_dtv
				.setText(preScale+"");
//						valueSourceSpeakerPrescaler[1].replaceFirst("0x(.*)",
//								"$1"), 16)));

		MtkTvFApiAudio.getInstance().setCurrentAudioSrc(AudioInputSource.CVBS);
		preScale = MtkTvFApiAudio.getInstance().getPrescale(EnumSoundMode.values()[SOUND_MODE_ID] ,EnumAudOutputType.SPEAKER);
		seekBarPS_av
				.setProgress((int)(((preScale + 10))*8));
//						.replaceFirst("0x(.*)", "$1"), 16));
		valueTextPS_av
				.setText(preScale+"");
//						valueSourceSpeakerPrescaler[2].replaceFirst("0x(.*)",
//								"$1"), 16)));

		seekBarPS_ypbpr
				.setProgress(0);//Integer.parseInt(valueSourceSpeakerPrescaler[3]));
//						.replaceFirst("0x(.*)", "$1"), 16));
		valueTextPS_ypbpr
				.setText(0+"");//Integer.toString(Integer.parseInt(valueSourceSpeakerPrescaler[3])));
//						valueSourceSpeakerPrescaler[3].replaceFirst("0x(.*)",
//								"$1"), 16)));

		seekBarPS_pc
				.setProgress(0);//Integer.parseInt(valueSourceSpeakerPrescaler[4]));
//						.replaceFirst("0x(.*)", "$1"), 16));
		valueTextPS_pc
				.setText(0+"");//Integer.toString(Integer.parseInt(valueSourceSpeakerPrescaler[4])));
//						valueSourceSpeakerPrescaler[4].replaceFirst("0x(.*)",
//								"$1"), 16)));

		MtkTvFApiAudio.getInstance().setCurrentAudioSrc(AudioInputSource.HDMI);
		preScale = MtkTvFApiAudio.getInstance().getPrescale(EnumSoundMode.values()[SOUND_MODE_ID] ,EnumAudOutputType.SPEAKER);
		seekBarPS_hdmi
				.setProgress((int)(((preScale + 10))*8));
//						.replaceFirst("0x(.*)", "$1"), 16));
		valueTextPS_hdmi
				.setText(preScale+"");
//						valueSourceSpeakerPrescaler[5].replaceFirst("0x(.*)",
//								"$1"), 16)));

		MtkTvFApiAudio.getInstance().setCurrentAudioSrc(AudioInputSource.MM);
		preScale = MtkTvFApiAudio.getInstance().getPrescale(EnumSoundMode.values()[SOUND_MODE_ID] ,EnumAudOutputType.SPEAKER);
		seekBarPS_mm
				.setProgress((int)(((preScale + 10))*8));
//						.replaceFirst("0x(.*)", "$1"), 16));
		valueTextPS_mm
				.setText(preScale+"");
//						valueSourceSpeakerPrescaler[6].replaceFirst("0x(.*)",
//								"$1"), 16)));

		seekBarPS_net
				.setProgress(0);//Integer.parseInt(valueSourceSpeakerPrescaler[7]));
//						.replaceFirst("0x(.*)", "$1"), 16));
		valueTextPS_net
				.setText(0+"");//Integer.toString(Integer.parseInt(valueSourceSpeakerPrescaler[7])));
//						valueSourceSpeakerPrescaler[7].replaceFirst("0x(.*)",
//								"$1"), 16)));


		setCurrentAudioSrcByinputsource();
		
		SoundEffectParams argSoundEffect = new SoundEffectParams();
		MtkTvFApiAudio.getInstance().getAudioIniBasicSndParams(EnumSoundMode.values()[SOUND_MODE_ID],argSoundEffect);


		edittext_pre_limiterthreshold.setText(argSoundEffect.DrcAllBand_TargetLevel+"");
	}

	public boolean saveChangePreScalerProgress(int src_ID, int progress) {
		// TODO Auto-generated method stub
		
		String strTemp = Integer.toHexString(progress);
		valueSourceSpeakerPrescaler[src_ID] = "0x" + strTemp;
		progress = progress - 80;
		Log.d(TAG,"saveChangePreScalerProgress progress "+progress);
		AudioInputSource curAudioSource = MtkTvFApiAudio.getInstance().getCurrentAudioSrc();
		Log.d(TAG,"curAudioSource "+curAudioSource);
		switch(src_ID){
		case 0:
            if(curAudioSource != AudioInputSource.ATV){
            	MtkTvFApiAudio.getInstance().setCurrentAudioSrc(AudioInputSource.ATV);
            }
            MtkTvFApiAudio.getInstance().setPrescale(EnumSoundMode.values()[SOUND_MODE_ID] ,EnumAudOutputType.SPEAKER,((double)progress)/8);
            break;
		case 1:
			if(curAudioSource != AudioInputSource.DTV){
            	MtkTvFApiAudio.getInstance().setCurrentAudioSrc(AudioInputSource.DTV);
            }
            MtkTvFApiAudio.getInstance().setPrescale(EnumSoundMode.values()[SOUND_MODE_ID] ,EnumAudOutputType.SPEAKER,((double)progress)/8);
            break;
		case 2:
			if(curAudioSource != AudioInputSource.CVBS){
            	MtkTvFApiAudio.getInstance().setCurrentAudioSrc(AudioInputSource.CVBS);
            }
            MtkTvFApiAudio.getInstance().setPrescale(EnumSoundMode.values()[SOUND_MODE_ID] ,EnumAudOutputType.SPEAKER,((double)progress)/8);
            break;
		case 5:
            if(curAudioSource != AudioInputSource.HDMI){
            	MtkTvFApiAudio.getInstance().setCurrentAudioSrc(AudioInputSource.HDMI);
            }
            MtkTvFApiAudio.getInstance().setPrescale(EnumSoundMode.values()[SOUND_MODE_ID] ,EnumAudOutputType.SPEAKER,((double)progress)/8);
            break;
		case 6:
			if(curAudioSource != AudioInputSource.MM){
            	MtkTvFApiAudio.getInstance().setCurrentAudioSrc(AudioInputSource.MM);
            }
            MtkTvFApiAudio.getInstance().setPrescale(EnumSoundMode.values()[SOUND_MODE_ID] ,EnumAudOutputType.SPEAKER,((double)progress)/8);
            break;
		}
		try {
//			SoundEffectParams argSoundEffect = new SoundEffectParams();
//			MtkTvFApiAudio.getInstance().getAudioIniBasicSndParams(argSoundEffect);
//			argSoundEffect.PreScale = progress;
//			MtkTvFApiAudio.getInstance().setBasicSoundEffect(EnumBasicSoundType.E_FAPI_AUD_BASIC_SND_PRESCALE, argSoundEffect);
//			Log.d(TAG,"PreScale set value " + progress);
//			MtkTvFApiAudio.getInstance().setPrescale((short)progress);
//			mTvMiscManager.DspCmdSetSourcePreScale((byte) src_ID, (byte) progress);
//			TVManager.getInstance(AQService.this).getSoundManager()
//					.DspCmdSetSourcePreScale((byte) src_ID, (byte) progress);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		setCurrentAudioSrcByinputsource();

		return true;
	}

	private void findViewsByIdAndInitTheirAppearanceOnPrescaler() {
		// TODO Auto-generated method stub
		seekBarPS_atv = (SeekBar) mTabHost_aq.findViewById(R.id.seekBar_SP1);
		seekBarPS_dtv = (SeekBar) mTabHost_aq.findViewById(R.id.seekBar_SP2);
		seekBarPS_av = (SeekBar) mTabHost_aq.findViewById(R.id.seekBar_SP3);
		seekBarPS_ypbpr = (SeekBar) mTabHost_aq.findViewById(R.id.seekBar_SP4);
		seekBarPS_pc = (SeekBar) mTabHost_aq.findViewById(R.id.seekBar_SP5);
		seekBarPS_hdmi = (SeekBar) mTabHost_aq.findViewById(R.id.seekBar_SP6);
		seekBarPS_mm = (SeekBar) mTabHost_aq.findViewById(R.id.seekBar_SP7);
		seekBarPS_net = (SeekBar) mTabHost_aq.findViewById(R.id.seekBar_SP8);

		valueTextPS_atv = (TextView) mTabHost_aq
				.findViewById(R.id.preScaler_atv_value);
		valueTextPS_dtv = (TextView) mTabHost_aq
				.findViewById(R.id.preScaler_dtv_value);
		valueTextPS_av = (TextView) mTabHost_aq
				.findViewById(R.id.preScaler_av_value);
		valueTextPS_ypbpr = (TextView) mTabHost_aq
				.findViewById(R.id.preScaler_ypbpr_value);
		valueTextPS_pc = (TextView) mTabHost_aq
				.findViewById(R.id.preScaler_pc_value);
		valueTextPS_hdmi = (TextView) mTabHost_aq
				.findViewById(R.id.preScaler_hdmi_value);
		valueTextPS_mm = (TextView) mTabHost_aq
				.findViewById(R.id.preScaler_mm_value);
		valueTextPS_net = (TextView) mTabHost_aq
				.findViewById(R.id.preScaler_net_value);
		
		edittext_pre_limiterthreshold = (EditText) mTabHost_aq
				.findViewById(R.id.edit_pre_limiterthreshold);
	}

	private void getAllValuesAboutPrescaler() {
		// TODO Auto-generated method stub
		// prescaler the initial value of the data is obtained from InitAQdata()
	}

	// ============================================================================================================
	// ================================== EQ
	// ======================================================================
	// ============================================================================================================
//	private static final String[] soundModes = { "标准模式", "晚间剧场", "超级影院", "文字阅读","高质音乐","劲爆体育","急速游戏" };
	
// ============================================================================================================
// ==================================NEW  Output Gain
// ============================================================
// ============================================================================================================	
	

	// ============================================================================================================
	// ================================== Surround Sound
	// ==========================================================
	// ============================================================================================================
	
	// ============================================================================================================
	// ================================== PEQ
	// ==========================================================
	// ============================================================================================================
	Switch switch_peq_PEQ;
	EditText  edit_fre_band1,edit_fre_band2,edit_fre_band3,edit_fre_band4,edit_fre_band5,
	          edit_fre_band6,edit_fre_band7,edit_fre_band8,edit_fre_band9,edit_fre_band10,
	          edit_fre_band11,edit_fre_band12,edit_fre_band13;
	EditText  edit_eqvalue_band1,edit_eqvalue_band2,edit_eqvalue_band3,edit_eqvalue_band4,edit_eqvalue_band5,
	          edit_eqvalue_band6,edit_eqvalue_band7,edit_eqvalue_band8,edit_eqvalue_band9,edit_eqvalue_band10,
	          edit_eqvalue_band11,edit_eqvalue_band12,edit_eqvalue_band13;
	SeekBar  seekBar_peqgain_band1,seekBar_peqgain_band2,seekBar_peqgain_band3,seekBar_peqgain_band4,seekBar_peqgain_band5,
	         seekBar_peqgain_band6,seekBar_peqgain_band7,seekBar_peqgain_band8,seekBar_peqgain_band9,seekBar_peqgain_band10,
	         seekBar_peqgain_band11,seekBar_peqgain_band12,seekBar_peqgain_band13;
	TextView TextView_peqgain_band1,TextView_peqgain_band2,TextView_peqgain_band3,TextView_peqgain_band4,TextView_peqgain_band5,
	         TextView_peqgain_band6,TextView_peqgain_band7,TextView_peqgain_band8,TextView_peqgain_band9,TextView_peqgain_band10,
	         TextView_peqgain_band11,TextView_peqgain_band12,TextView_peqgain_band13;
	public void initpeq() {
		switch_peq_PEQ = (Switch) mTabHost_aq.findViewById(R.id.switch_peq_peq);
		OnCheckedChangeListener checkedListener_SwitchPeq_peq= new OnCheckedChangeListener() {

			public void onCheckedChanged(CompoundButton buttonView,
					boolean isChecked) {
				setPEQPEQEnable(isChecked);											// isChecked
				if (isChecked) {
					switch_peq_PEQ.setChecked(isChecked);
				}
				
				
			}

		};
		switch_peq_PEQ.setOnCheckedChangeListener(checkedListener_SwitchPeq_peq);
		switch_peq_PEQ.setOnFocusChangeListener(new OnFocusChangeListener() {

			@Override
			public void onFocusChange(View v, boolean isFocus) {
				// TODO Auto-generated method stub
				if (isFocus) {
					if (!switchFocus) {
						focusEditText.requestFocus();
					}
				}
			}

		});
		
		edit_fre_band1 = (EditText) mTabHost_aq.findViewById(R.id.edit_peq_band1_freq);
		edit_fre_band2 = (EditText) mTabHost_aq.findViewById(R.id.edit_peq_band2_freq);
		edit_fre_band3 = (EditText) mTabHost_aq.findViewById(R.id.edit_peq_band3_freq);
		edit_fre_band4 = (EditText) mTabHost_aq.findViewById(R.id.edit_peq_band4_freq);
		edit_fre_band5 = (EditText) mTabHost_aq.findViewById(R.id.edit_peq_band5_freq);
		edit_fre_band6 = (EditText) mTabHost_aq.findViewById(R.id.edit_peq_band6_freq);
		edit_fre_band7 = (EditText) mTabHost_aq.findViewById(R.id.edit_peq_band7_freq);
		edit_fre_band8 = (EditText) mTabHost_aq.findViewById(R.id.edit_peq_band8_freq);
		edit_fre_band9 = (EditText) mTabHost_aq.findViewById(R.id.edit_peq_band9_freq);
		edit_fre_band10 = (EditText) mTabHost_aq.findViewById(R.id.edit_peq_band10_freq);
		edit_fre_band11 = (EditText) mTabHost_aq.findViewById(R.id.edit_peq_band11_freq);
		edit_fre_band12 = (EditText) mTabHost_aq.findViewById(R.id.edit_peq_band12_freq);
		edit_fre_band13 = (EditText) mTabHost_aq.findViewById(R.id.edit_peq_band13_freq);
		
		edit_eqvalue_band1 = (EditText) mTabHost_aq.findViewById(R.id.edit_peq_band1_eq_value);
		edit_eqvalue_band2 = (EditText) mTabHost_aq.findViewById(R.id.edit_peq_band2_eq_value);
		edit_eqvalue_band3 = (EditText) mTabHost_aq.findViewById(R.id.edit_peq_band3_eq_value);
		edit_eqvalue_band4 = (EditText) mTabHost_aq.findViewById(R.id.edit_peq_band4_eq_value);
		edit_eqvalue_band5 = (EditText) mTabHost_aq.findViewById(R.id.edit_peq_band5_eq_value);
		edit_eqvalue_band6 = (EditText) mTabHost_aq.findViewById(R.id.edit_peq_band6_eq_value);
		edit_eqvalue_band7 = (EditText) mTabHost_aq.findViewById(R.id.edit_peq_band7_eq_value);
		edit_eqvalue_band8 = (EditText) mTabHost_aq.findViewById(R.id.edit_peq_band8_eq_value);
		edit_eqvalue_band9 = (EditText) mTabHost_aq.findViewById(R.id.edit_peq_band9_eq_value);
		edit_eqvalue_band10 = (EditText) mTabHost_aq.findViewById(R.id.edit_peq_band10_eq_value);
		edit_eqvalue_band11 = (EditText) mTabHost_aq.findViewById(R.id.edit_peq_band11_eq_value);
		edit_eqvalue_band12 = (EditText) mTabHost_aq.findViewById(R.id.edit_peq_band12_eq_value);
		edit_eqvalue_band13 = (EditText) mTabHost_aq.findViewById(R.id.edit_peq_band13_eq_value);
		
		seekBar_peqgain_band1 = (SeekBar) mTabHost_aq.findViewById(R.id.seekBar_peq_band1_eq_gain);
		seekBar_peqgain_band2 = (SeekBar) mTabHost_aq.findViewById(R.id.seekBar_peq_band2_eq_gain);
		seekBar_peqgain_band3 = (SeekBar) mTabHost_aq.findViewById(R.id.seekBar_peq_band3_eq_gain);
		seekBar_peqgain_band4 = (SeekBar) mTabHost_aq.findViewById(R.id.seekBar_peq_band4_eq_gain);
		seekBar_peqgain_band5 = (SeekBar) mTabHost_aq.findViewById(R.id.seekBar_peq_band5_eq_gain);
		seekBar_peqgain_band6 = (SeekBar) mTabHost_aq.findViewById(R.id.seekBar_peq_band6_eq_gain);
		seekBar_peqgain_band7 = (SeekBar) mTabHost_aq.findViewById(R.id.seekBar_peq_band7_eq_gain);
		seekBar_peqgain_band8 = (SeekBar) mTabHost_aq.findViewById(R.id.seekBar_peq_band8_eq_gain);
		seekBar_peqgain_band9 = (SeekBar) mTabHost_aq.findViewById(R.id.seekBar_peq_band9_eq_gain);
		seekBar_peqgain_band10 = (SeekBar) mTabHost_aq.findViewById(R.id.seekBar_peq_band10_eq_gain);
		seekBar_peqgain_band11 = (SeekBar) mTabHost_aq.findViewById(R.id.seekBar_peq_band11_eq_gain);
		seekBar_peqgain_band12 = (SeekBar) mTabHost_aq.findViewById(R.id.seekBar_peq_band12_eq_gain);
		seekBar_peqgain_band13 = (SeekBar) mTabHost_aq.findViewById(R.id.seekBar_peq_band13_eq_gain);
		
		TextView_peqgain_band1 = (TextView) mTabHost_aq.findViewById(R.id.peq_band1_eq_gain_value);
		TextView_peqgain_band2 = (TextView) mTabHost_aq.findViewById(R.id.peq_band2_eq_gain_value);
		TextView_peqgain_band3 = (TextView) mTabHost_aq.findViewById(R.id.peq_band3_eq_gain_value);
		TextView_peqgain_band4 = (TextView) mTabHost_aq.findViewById(R.id.peq_band4_eq_gain_value);
		TextView_peqgain_band5 = (TextView) mTabHost_aq.findViewById(R.id.peq_band5_eq_gain_value);
		TextView_peqgain_band6 = (TextView) mTabHost_aq.findViewById(R.id.peq_band6_eq_gain_value);
		TextView_peqgain_band7 = (TextView) mTabHost_aq.findViewById(R.id.peq_band7_eq_gain_value);
		TextView_peqgain_band8 = (TextView) mTabHost_aq.findViewById(R.id.peq_band8_eq_gain_value);
		TextView_peqgain_band9 = (TextView) mTabHost_aq.findViewById(R.id.peq_band9_eq_gain_value);
		TextView_peqgain_band10 = (TextView) mTabHost_aq.findViewById(R.id.peq_band10_eq_gain_value);
		TextView_peqgain_band11 = (TextView) mTabHost_aq.findViewById(R.id.peq_band11_eq_gain_value);
		TextView_peqgain_band12 = (TextView) mTabHost_aq.findViewById(R.id.peq_band12_eq_gain_value);
		TextView_peqgain_band13 = (TextView) mTabHost_aq.findViewById(R.id.peq_band13_eq_gain_value);
		
		edit_fre_band1.setOnFocusChangeListener(focusChangeListener_PEQFRE_BAND1);
		edit_fre_band2.setOnFocusChangeListener(focusChangeListener_PEQFRE_BAND2);
		edit_fre_band3.setOnFocusChangeListener(focusChangeListener_PEQFRE_BAND3);
		edit_fre_band4.setOnFocusChangeListener(focusChangeListener_PEQFRE_BAND4);
		edit_fre_band5.setOnFocusChangeListener(focusChangeListener_PEQFRE_BAND5);
		edit_fre_band6.setOnFocusChangeListener(focusChangeListener_PEQFRE_BAND6);
		edit_fre_band7.setOnFocusChangeListener(focusChangeListener_PEQFRE_BAND7);
		edit_fre_band8.setOnFocusChangeListener(focusChangeListener_PEQFRE_BAND8);
		edit_fre_band9.setOnFocusChangeListener(focusChangeListener_PEQFRE_BAND9);
		edit_fre_band10.setOnFocusChangeListener(focusChangeListener_PEQFRE_BAND10);
		edit_fre_band11.setOnFocusChangeListener(focusChangeListener_PEQFRE_BAND11);
		edit_fre_band12.setOnFocusChangeListener(focusChangeListener_PEQFRE_BAND12);
		edit_fre_band13.setOnFocusChangeListener(focusChangeListener_PEQFRE_BAND13);
		edit_eqvalue_band1.setOnFocusChangeListener(focusChangeListener_EQVALUE_BAND1);
		edit_eqvalue_band2.setOnFocusChangeListener(focusChangeListener_EQVALUE_BAND2);
		edit_eqvalue_band3.setOnFocusChangeListener(focusChangeListener_EQVALUE_BAND3);
		edit_eqvalue_band4.setOnFocusChangeListener(focusChangeListener_EQVALUE_BAND4);
		edit_eqvalue_band5.setOnFocusChangeListener(focusChangeListener_EQVALUE_BAND5);
		edit_eqvalue_band6.setOnFocusChangeListener(focusChangeListener_EQVALUE_BAND6);
		edit_eqvalue_band7.setOnFocusChangeListener(focusChangeListener_EQVALUE_BAND7);
		edit_eqvalue_band8.setOnFocusChangeListener(focusChangeListener_EQVALUE_BAND8);
		edit_eqvalue_band9.setOnFocusChangeListener(focusChangeListener_EQVALUE_BAND9);
		edit_eqvalue_band10.setOnFocusChangeListener(focusChangeListener_EQVALUE_BAND10);
		edit_eqvalue_band11.setOnFocusChangeListener(focusChangeListener_EQVALUE_BAND11);
		edit_eqvalue_band12.setOnFocusChangeListener(focusChangeListener_EQVALUE_BAND12);
		edit_eqvalue_band13.setOnFocusChangeListener(focusChangeListener_EQVALUE_BAND13);
		seekBar_peqgain_band1.setOnSeekBarChangeListener(SeekBarListener_PEQGain_band1);
		seekBar_peqgain_band2.setOnSeekBarChangeListener(SeekBarListener_PEQGain_band2);
		seekBar_peqgain_band3.setOnSeekBarChangeListener(SeekBarListener_PEQGain_band3);
		seekBar_peqgain_band4.setOnSeekBarChangeListener(SeekBarListener_PEQGain_band4);
		seekBar_peqgain_band5.setOnSeekBarChangeListener(SeekBarListener_PEQGain_band5);
		seekBar_peqgain_band6.setOnSeekBarChangeListener(SeekBarListener_PEQGain_band6);
		seekBar_peqgain_band7.setOnSeekBarChangeListener(SeekBarListener_PEQGain_band7);
		seekBar_peqgain_band8.setOnSeekBarChangeListener(SeekBarListener_PEQGain_band8);
		seekBar_peqgain_band9.setOnSeekBarChangeListener(SeekBarListener_PEQGain_band9);
		seekBar_peqgain_band10.setOnSeekBarChangeListener(SeekBarListener_PEQGain_band10);
		seekBar_peqgain_band11.setOnSeekBarChangeListener(SeekBarListener_PEQGain_band11);
		seekBar_peqgain_band12.setOnSeekBarChangeListener(SeekBarListener_PEQGain_band12);
		seekBar_peqgain_band13.setOnSeekBarChangeListener(SeekBarListener_PEQGain_band13);
		
		seekBar_peqgain_band1.setOnKeyListener(keyListener_seerbar_PEQGAIN);
		seekBar_peqgain_band2.setOnKeyListener(keyListener_seerbar_PEQGAIN);
		seekBar_peqgain_band3.setOnKeyListener(keyListener_seerbar_PEQGAIN);
		seekBar_peqgain_band4.setOnKeyListener(keyListener_seerbar_PEQGAIN);
		seekBar_peqgain_band5.setOnKeyListener(keyListener_seerbar_PEQGAIN);
		seekBar_peqgain_band6.setOnKeyListener(keyListener_seerbar_PEQGAIN);
		seekBar_peqgain_band7.setOnKeyListener(keyListener_seerbar_PEQGAIN);
		seekBar_peqgain_band8.setOnKeyListener(keyListener_seerbar_PEQGAIN);
		seekBar_peqgain_band9.setOnKeyListener(keyListener_seerbar_PEQGAIN);
		seekBar_peqgain_band10.setOnKeyListener(keyListener_seerbar_PEQGAIN);
		seekBar_peqgain_band11.setOnKeyListener(keyListener_seerbar_PEQGAIN);
		seekBar_peqgain_band12.setOnKeyListener(keyListener_seerbar_PEQGAIN);
		seekBar_peqgain_band13.setOnKeyListener(keyListener_seerbar_PEQGAIN);
		
		refreshViewsOnPeqPeq();
		
		
		
	}
	// ============================================================================================================
	// ================================== save and eport
	// =========================================================
	// ============================================================================================================
	Button  ButtonpreExportData, ButtonpeqExportData, ButtonotherExportData;
	public void initexport() {
		ButtonpreExportData = (Button) mTabHost_aq.findViewById(R.id.pre_ExportAQData);
		ButtonpeqExportData = (Button) mTabHost_aq.findViewById(R.id.peq_ExportAQData);
		ButtonotherExportData = (Button) mTabHost_aq.findViewById(R.id.other_ExportAQData);
		ButtonpreExportData.setOnClickListener(OutputResult);
		ButtonpreExportData.setOnFocusChangeListener(new OnFocusChangeListener() {

			@Override
			public void onFocusChange(View v, boolean isFocus) {
				// TODO Auto-generated method stub
				if (isFocus) {
					if (!switchFocus) {
						focusEditText.requestFocus();
					}
				}
			}

		});
		ButtonpeqExportData.setOnClickListener(OutputResult);
		ButtonpeqExportData.setOnFocusChangeListener(new OnFocusChangeListener() {

			@Override
			public void onFocusChange(View v, boolean isFocus) {
				// TODO Auto-generated method stub
				if (isFocus) {
					if (!switchFocus) {
						focusEditText.requestFocus();
					}
				}
			}

		});
		ButtonotherExportData.setOnClickListener(OutputResult);
		ButtonotherExportData.setOnFocusChangeListener(new OnFocusChangeListener() {

			@Override
			public void onFocusChange(View v, boolean isFocus) {
				// TODO Auto-generated method stub
				if (isFocus) {
					if (!switchFocus) {
						focusEditText.requestFocus();
					}
				}
			}

		});
	}
	
	// ============================================================================================================
	// ================================== Other & Version
	// =========================================================
	// ============================================================================================================
	EditText edit_AQID, edit_Version, edit_Limiter, edit_NRThreshold;
	Switch switch_hpf;
	EditText HPF_Gain, HPF_Fre, HPF_QValue;
	FlowRadioGroup band_rGroup;
	int peqBandNum = 0;
	TextView TextView_Limiter;
	Switch switch_Limiter;
	ArrayAdapter<String> adapter_PEQ;
	private String[] peqArray = {"Band1", "Band2", "Band3", "Band4", "Band5", "Band6", "Band7", "Band8", "Band9", "Band10", "Band11", "Band12", "Band13" } ;
	public void initOthers() {
		edit_AQID = (EditText) mTabHost_aq.findViewById(R.id.edit_aqid);
		edit_Version = (EditText) mTabHost_aq.findViewById(R.id.edit_version);
		edit_Limiter = (EditText) mTabHost_aq
				.findViewById(R.id.edit_limiterthreshold);
		edit_NRThreshold = (EditText) mTabHost_aq
				.findViewById(R.id.edit_nrthreshold);
		TextView_Limiter = (TextView)mTabHost_aq
				.findViewById(R.id.textview_limiterthreshold);

//		edit_AQID.setOnFocusChangeListener(focusChangeListener_AQID);
		edit_Version.setOnFocusChangeListener(focusChangeListener_Version);
		edit_Limiter.setOnFocusChangeListener(focusChangeListener_Limiter);
		edit_NRThreshold
				.setOnFocusChangeListener(focusChangeListener_NRThreshold);

//		edit_AQID.setOnKeyListener(keyListener_AQID);
		edit_Version.setOnKeyListener(keyListener_Version);
		edit_Limiter.setOnKeyListener(keyListener_Limiter);
		edit_NRThreshold.setOnKeyListener(keyListener_NRThreshold);
		
		
		//limiter switch
				switch_Limiter = (Switch) mTabHost_aq.findViewById(R.id.switch3);//
				
				OnCheckedChangeListener checkedListener_SwitchLimiter= new OnCheckedChangeListener() {

					public void onCheckedChanged(CompoundButton buttonView,
							boolean isChecked) {
						saveDrcSwitchToAllSource(isChecked);
//						AudioInputSource curAudioSource = MtkTvFApiAudio.getInstance().getCurrentAudioSrc();
//						BasicSoundEnableStatus sndStatus = new BasicSoundEnableStatus();
//						MtkTvFApiAudio.getInstance().getBasicSoundEnableStatus(EnumSoundMode.values()[SOUND_MODE_ID], sndStatus);
//						if (isChecked) {
//							valueLimiterThreshold[0] = "TRUE";
//							sndStatus.bDrcEnable = 1;
//							MtkTvFApiAudio.getInstance().enableBasicSoundEffect(EnumSoundMode.values()[SOUND_MODE_ID], sndStatus);
//							try {
////								String limiter = MtkTvFApiAudio.getInstance().getAudioIniParameter(MTKTV_FAPI_INI_TYPE_AUDIO_ENUM.E_MTK_FAPI_INI_TYPE_DEFAULT_BASIC_SOUND_EFFECT, MTKTV_FAPI_KEY_TYPE_AUDIO_ENUM.E_MTK_FAPI_KEY_TYPE_DTS_SRS_THEATERSOUND3D_HARD_LIMITER_ENABLE);
////								BasicSoundEnableStatus status = new BasicSoundEnableStatus();
////								status.bPeqEnable = isChecked?1:0;
////								MtkTvFApiAudio.getInstance().enableBasicSoundEffect(EnumSoundMode.values()[SOUND_MODE_ID], status);
////								mTvMiscManager.SetLimiterThreshold(isChecked,Integer.parseInt(
////										valueLimiterThreshold[1].replaceFirst("0x(.*)", "$1"), 16));
//
////								TVManager.getInstance(AQService.this).getSoundManager()
////										.DspCmdSetLimiterThreshold(isChecked,Integer.parseInt(
////												valueLimiterThreshold[1].replaceFirst("0x(.*)", "$1"), 16));
//
//							} catch (Exception e) {
//								// TODO Auto-generated catch block
//								e.printStackTrace();
//							}
//							
//							
//						} else {
//							valueLimiterThreshold[0] = "FALSE";
//							sndStatus.bDrcEnable = 0;
//							MtkTvFApiAudio.getInstance().enableBasicSoundEffect(EnumSoundMode.values()[SOUND_MODE_ID], sndStatus);
//						}
						Log.v(TAG, valueLimiterThreshold[0]);
						
						edit_Limiter.setEnabled(isChecked);
						
						
					}

				};
				switch_Limiter.setOnCheckedChangeListener(checkedListener_SwitchLimiter);
				switch_Limiter.setOnFocusChangeListener(new OnFocusChangeListener() {

					@Override
					public void onFocusChange(View v, boolean isFocus) {
						// TODO Auto-generated method stub
						if (isFocus) {
							if (!switchFocus) {
								focusEditText.requestFocus();
							}
						}
					}

				});
				
				band_rGroup = (FlowRadioGroup) mTabHost_aq
						.findViewById(R.id.RadioGroup2);
				for(int i=0;i<peqArray.length;i++){
					RadioButton tempButton = new RadioButton(getApplicationContext());
					tempButton.setId(i);
				    tempButton.setBackgroundResource(R.drawable.pq_button_bg);	// 设置RadioButton的背景图片
//				    tempButton.setButtonDrawable(R.drawable.xxx);			// 设置按钮的样式
//				    tempButton.setPadding(80, 0, 0, 0);           		// 设置文字距离按钮四周的距离 
				    tempButton.setText(peqArray[i]);
				    tempButton.setTextColor(getResources().getColor(R.color.white));
				    //sp_colorMode.addView(tempButton, LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
				    band_rGroup.addView(tempButton);
				}
		
				
				band_rGroup.check(peqBandNum);
				band_rGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
					
					@Override
					public void onCheckedChanged(RadioGroup group, int checkedId) {
						// TODO Auto-generated method stub
						peqBandNum = checkedId;
						refreshViewsOnPeq(peqBandNum);
					}
				});

						
		setAndDisplayOthresValue();
		
		switch_hpf = (Switch) mTabHost_aq.findViewById(R.id.switch_hpf);
		switch_hpf.setOnCheckedChangeListener(checkedListener_HPF);
		switch_hpf.setOnFocusChangeListener(new OnFocusChangeListener() {

			@Override
			public void onFocusChange(View v, boolean isFocus) {
				// TODO Auto-generated method stub
				if (isFocus) {
					if (!switchFocus) {
						focusEditText.requestFocus();
					}
				}
			}

		});
		
		HPF_Gain = (EditText) mTabHost_aq.findViewById(R.id.edit_hpf_gain);
		HPF_Fre = (EditText) mTabHost_aq.findViewById(R.id.edit_hpf_fre);
		HPF_QValue = (EditText) mTabHost_aq.findViewById(R.id.edit_hpf_qvalue);
		HPF_Gain.setOnFocusChangeListener(focusChangeListener_HPFGAIN);
		HPF_Fre.setOnFocusChangeListener(focusChangeListener_HPFFRE);
		HPF_QValue.setOnFocusChangeListener(focusChangeListener_HPFQVALUE);
		

		switch_PEQ = (Switch) mTabHost_aq.findViewById(R.id.switch1);
		switch_PEQ.setOnCheckedChangeListener(checkedListener_PEQ);
		switch_PEQ.setOnFocusChangeListener(new OnFocusChangeListener() {

			@Override
			public void onFocusChange(View v, boolean isFocus) {
				// TODO Auto-generated method stub
				if (isFocus) {
					if (!switchFocus) {
						focusEditText.requestFocus();
					}
				}
			}

		});
		edit_PEQBand_1 = (EditText) mTabHost_aq
				.findViewById(R.id.edit_peq_band1);
		edit_PEQBand_2 = (EditText) mTabHost_aq
				.findViewById(R.id.edit_peq_band2);
		edit_PEQBand_3 = (EditText) mTabHost_aq
				.findViewById(R.id.edit_peq_band3);
		edit_PEQFrequenceH_1 = (EditText) mTabHost_aq
				.findViewById(R.id.edit_peq_freq_h1);
		edit_PEQFrequenceH_2 = (EditText) mTabHost_aq
				.findViewById(R.id.edit_peq_freq_h2);
		edit_PEQFrequenceH_3 = (EditText) mTabHost_aq
				.findViewById(R.id.edit_peq_freq_h3);
		edit_PEQFrequenceL_1 = (EditText) mTabHost_aq
				.findViewById(R.id.edit_peq_freq_l1);
		edit_PEQFrequenceL_2 = (EditText) mTabHost_aq
				.findViewById(R.id.edit_peq_freq_l2);
		edit_PEQFrequenceL_3 = (EditText) mTabHost_aq
				.findViewById(R.id.edit_peq_freq_l3);
		edit_EQ_Value_1 = (EditText) mTabHost_aq
				.findViewById(R.id.edit_peq_eqvalue1);
		edit_EQ_Value_2 = (EditText) mTabHost_aq
				.findViewById(R.id.edit_peq_eqvalue2);
		edit_EQ_Value_3 = (EditText) mTabHost_aq
				.findViewById(R.id.edit_peq_eqvalue3);
		edit_PEQGain_1 = (EditText) mTabHost_aq
				.findViewById(R.id.edit_peq_eqgain1);
		edit_PEQGain_2 = (EditText) mTabHost_aq
				.findViewById(R.id.edit_peq_eqgain2);
		edit_PEQGain_3 = (EditText) mTabHost_aq
				.findViewById(R.id.edit_peq_eqgain3);

		edit_PEQBand_1.setOnFocusChangeListener(focusChangeListener_PEQBand_1);
		edit_PEQBand_2.setOnFocusChangeListener(focusChangeListener_PEQBand_2);
		edit_PEQBand_3.setOnFocusChangeListener(focusChangeListener_PEQBand_3);
		edit_PEQFrequenceH_1
				.setOnFocusChangeListener(focusChangeListener_PEQFrequenceH_1);
		edit_PEQFrequenceH_2
				.setOnFocusChangeListener(focusChangeListener_PEQFrequenceH_2);
		edit_PEQFrequenceH_3
				.setOnFocusChangeListener(focusChangeListener_PEQFrequenceH_3);
		edit_PEQFrequenceL_1
				.setOnFocusChangeListener(focusChangeListener_PEQFrequenceL_1);
		edit_PEQFrequenceL_2
				.setOnFocusChangeListener(focusChangeListener_PEQFrequenceL_2);
		edit_PEQFrequenceL_3
				.setOnFocusChangeListener(focusChangeListener_PEQFrequenceL_3);
		edit_EQ_Value_1
				.setOnFocusChangeListener(focusChangeListener_EQ_Value_1);
		edit_EQ_Value_2
				.setOnFocusChangeListener(focusChangeListener_EQ_Value_2);
		edit_EQ_Value_3
				.setOnFocusChangeListener(focusChangeListener_EQ_Value_3);
		edit_PEQGain_1.setOnFocusChangeListener(focusChangeListener_PEQGain_1);
		edit_PEQGain_2.setOnFocusChangeListener(focusChangeListener_PEQGain_2);
		edit_PEQGain_3.setOnFocusChangeListener(focusChangeListener_PEQGain_3);

		edit_PEQBand_1.setOnKeyListener(keyListener_PEQBand_1);
		edit_PEQBand_2.setOnKeyListener(keyListener_PEQBand_2);
		edit_PEQBand_3.setOnKeyListener(keyListener_PEQBand_3);
		edit_PEQFrequenceH_1.setOnKeyListener(keyListener_PEQFrequenceH_1);
		edit_PEQFrequenceH_2.setOnKeyListener(keyListener_PEQFrequenceH_2);
		edit_PEQFrequenceH_3.setOnKeyListener(keyListener_PEQFrequenceH_3);
		edit_PEQFrequenceL_1.setOnKeyListener(keyListener_PEQFrequenceL_1);
		edit_PEQFrequenceL_2.setOnKeyListener(keyListener_PEQFrequenceL_2);
		edit_PEQFrequenceL_3.setOnKeyListener(keyListener_PEQFrequenceL_3);
		edit_EQ_Value_1.setOnKeyListener(keyListener_EQ_Value_1);
		edit_EQ_Value_2.setOnKeyListener(keyListener_EQ_Value_2);
		edit_EQ_Value_3.setOnKeyListener(keyListener_EQ_Value_3);
		edit_PEQGain_1.setOnKeyListener(keyListener_PEQGain_1);
		edit_PEQGain_2.setOnKeyListener(keyListener_PEQGain_2);
		edit_PEQGain_3.setOnKeyListener(keyListener_PEQGain_3);
		
		switch_GEQ= (Switch) mTabHost_aq.findViewById(R.id.switch4);
		switch_GEQ.setOnCheckedChangeListener(checkedListener_GEQ);
		switch_GEQ.setOnFocusChangeListener(new OnFocusChangeListener() {

			@Override
			public void onFocusChange(View v, boolean isFocus) {
				// TODO Auto-generated method stub
				if (isFocus) {
					if (!switchFocus) {
						focusEditText.requestFocus();
					}
				}
			}

		});
//		switch_GEQ.setEnabled(false);
		switch_GEQ.setVisibility(View.GONE);
		
		edit_GEQ1= (EditText) mTabHost_aq
				.findViewById(R.id.edit_geq1);
		edit_GEQ2= (EditText) mTabHost_aq
				.findViewById(R.id.edit_geq2);
		edit_GEQ3= (EditText) mTabHost_aq
				.findViewById(R.id.edit_geq3);
		edit_GEQ4= (EditText) mTabHost_aq
				.findViewById(R.id.edit_geq4);
		edit_GEQ5= (EditText) mTabHost_aq
				.findViewById(R.id.edit_geq5);
		edit_GEQ1
		.setOnFocusChangeListener(focusChangeListener_GEQ1);
		edit_GEQ2
		.setOnFocusChangeListener(focusChangeListener_GEQ2);
		edit_GEQ3
		.setOnFocusChangeListener(focusChangeListener_GEQ3);
		edit_GEQ4
		.setOnFocusChangeListener(focusChangeListener_GEQ4);
		edit_GEQ5
		.setOnFocusChangeListener(focusChangeListener_GEQ5);


		setAndDisplayPEQStatus();
		refreshViewsOnPeq(peqBandNum);

		// ==============================================================================================================
		// // try {
		// TVManager.getInstance(AQService.this).getSoundManager().setMuteFlag(false);
		// } catch (IllegalValueException e) {
		// // TODO Auto-generated catch block
		// e.printStackTrace();
		// } catch (TVManagerNotInitException e) {
		// // TODO Auto-generated catch block
		// e.printStackTrace();
		// }

		// to crurent source
		try {
//			 int currentSource = MtkTvInputSourceBase.InputSourceRecord.INPS_TYPE_NUMERICAL_TV;//EnumInputSource.E_INPUT_SOURCE_ATV;

			String 	currentSource = MtkTvInputSource.getInstance().getCurrentInputSourceName();//mTvCommonManager.getCurrentInputSource();
//			EnumInputSource currentSource = EnumInputSource.E_INPUT_SOURCE_ATV;
			try {
//				currentSource = mTvCommonManager.getCurrentInputSource();
//				currentSource = TVManager
//						.getInstance(AQService.this)
//						.getSourceManager()
//						.getCurInputSource(
//								EnumPipInputSource.E_MAIN_INPUT_SOURCE);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

//			switch (currentSource) {
//			case E_INPUT_SOURCE_ATV: // /<TV input
//				SRC_ID = 0;
//				break;
//			case E_INPUT_SOURCE_DTV: // /<DTV
//			case E_INPUT_SOURCE_DTV2: // /<DTV
//			case E_INPUT_SOURCE_DTV3: // /<DTV	
//				SRC_ID = 1;
//				break;
//			case E_INPUT_SOURCE_CVBS: // /<AV 1
//			case E_INPUT_SOURCE_CVBS2: // /<AV 2
//			case E_INPUT_SOURCE_CVBS3: // /<AV 3
//			case E_INPUT_SOURCE_CVBS4: // /<AV 4
//			case E_INPUT_SOURCE_CVBS_MAX:// /<AV max
//			case E_INPUT_SOURCE_SVIDEO: // /<S-video 1
//			case E_INPUT_SOURCE_SVIDEO2: // /<S-video 2
//			case E_INPUT_SOURCE_SVIDEO_MAX: // /<S-video max
//			case E_INPUT_SOURCE_SCART: // /<Scart 1
//			case E_INPUT_SOURCE_SCART2: // /<Scart 2
//			case E_INPUT_SOURCE_SCART_MAX: // /<Scart max
//				SRC_ID = 2;
//				break;
//			case E_INPUT_SOURCE_YPBPR: // /<Component 1
//			case E_INPUT_SOURCE_YPBPR2: // /<Component 2
//			case E_INPUT_SOURCE_YPBPR_MAX: // /<Component max
//				SRC_ID = 3;
//				break;
//			case E_INPUT_SOURCE_VGA: // /<VGA input
//			case E_INPUT_SOURCE_VGA2: // /<VGA input
//			case E_INPUT_SOURCE_VGA3: // /<VGA input	
//				SRC_ID = 4;
//				break;
//			case E_INPUT_SOURCE_HDMI: // /<HDMI 1
//			case E_INPUT_SOURCE_HDMI2: // /<HDMI 2
//			case E_INPUT_SOURCE_HDMI3: // /<HDMI 3
//			case E_INPUT_SOURCE_HDMI4: // /<HDMI 4
//			case E_INPUT_SOURCE_HDMI_MAX: // /<HDMI max
//			case E_INPUT_SOURCE_DVI: // /<DVI 1
//			case E_INPUT_SOURCE_DVI2: // /<DVI 2
//			case E_INPUT_SOURCE_DVI3: // /<DVI 2
//			case E_INPUT_SOURCE_DVI4: // /<DVI 4
//			case E_INPUT_SOURCE_DVI_MAX: // /<DVI max
//				SRC_ID = 5;
//				break;
//			case  E_INPUT_SOURCE_STORAGE: // /<MEDIAPLAYER
//			case  E_INPUT_SOURCE_STORAGE2:
//				SRC_ID = 6;
//				break;
////				case E_INPUT_SOURCE_NETPLAYER:
////				SRC_ID = 7;
//				
//			case E_INPUT_SOURCE_NUM: // /<number of the source
//			case E_INPUT_SOURCE_NONE: // /<NULL input
//				SRC_ID = 7;//@wql
//				break;
//			default:
//				SRC_ID = 0;
//				break;
//
//			}

//			if(currentSource.equals(MtkTvInputSourceBase.INPUT_TYPE_ATV)){
//				SRC_ID = 0;
//			} else if(currentSource.equals(MtkTvInputSourceBase.INPUT_TYPE_DTV)){
//				SRC_ID = 1;
//			} else if(currentSource.equals(MtkTvInputSourceBase.INPUT_TYPE_SCART)
//					|| currentSource.equals(MtkTvInputSourceBase.INPUT_TYPE_AV)
//					|| currentSource.equals(MtkTvInputSourceBase.INPUT_TYPE_COMPOSITE)
//					||currentSource.equals(MtkTvInputSourceBase.INPUT_TYPE_SVIDEO)){
//				SRC_ID = 2;
//			} else if(currentSource.equals(MtkTvInputSourceBase.INPUT_TYPE_COMPONENT)){
//				SRC_ID = 3;
//			} else if(currentSource.equals(MtkTvInputSourceBase.INPUT_TYPE_VGA)){
//				SRC_ID = 4;
//			} else if(currentSource.equals(MtkTvInputSourceBase.INPUT_TYPE_HDMI)){
//				SRC_ID = 5;
//			} 
			getCurrentSourceID();

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		// Get current sound mode

		Log.v(TAG, "ASoundMode:" + String.valueOf(SOUND_MODE_ID));

		Log.v(TAG, "BSoundMode:" + String.valueOf(SOUND_MODE_ID));
	}

	public boolean setAndDisplayOthresValue() {

		String strTemp;
		SoundEffectParams argSoundEffect = new SoundEffectParams();
		MtkTvFApiAudio.getInstance().getAudioIniBasicSndParams(EnumSoundMode.values()[SOUND_MODE_ID],argSoundEffect);
		
		edit_AQID.setText(valueIniVersion[0].toString());
//		edit_AQID.setEnabled(false);

		edit_Version.setText(valueIniVersion[1].toString());

		strTemp = Integer.toString(Integer.parseInt(
				valueLimiterThreshold[1].replaceFirst("0x(.*)", "$1"), 16));
		Log.v("lhtest","setAndDisplayOthresValue argSoundEffect="+argSoundEffect.DrcAllBand_TargetLevel+" geqGain[0]="+argSoundEffect.geqGain[0]
				+" geqGain[1]="+argSoundEffect.geqGain[1]+" geqGain[2]="+argSoundEffect.geqGain[2]+" geqGain[3]="+argSoundEffect.geqGain[3]
						+" geqGain[4]="+argSoundEffect.geqGain[4]);
		edit_Limiter.setText(argSoundEffect.DrcAllBand_TargetLevel+"");
		GEQ[0] = argSoundEffect.geqGain[0];
		GEQ[1] = argSoundEffect.geqGain[1];
		GEQ[2] = argSoundEffect.geqGain[2];
		GEQ[3] = argSoundEffect.geqGain[3];
		GEQ[4] = argSoundEffect.geqGain[4];
		
		HPF[0] = argSoundEffect.HpfGain;
		HPF[1] = argSoundEffect.HpfFrequency;
		HPF[2] = argSoundEffect.HpfQValue;
		
		
		AudioInputSource curAudioSource = MtkTvFApiAudio.getInstance().getCurrentAudioSrc();
		BasicSoundEnableStatus sndStatus = new BasicSoundEnableStatus();
		MtkTvFApiAudio.getInstance().getBasicSoundEnableStatus(EnumSoundMode.values()[SOUND_MODE_ID], sndStatus);
		
	//switch limiter
		
		if (sndStatus.bDrcEnable == 0) {
			switch_Limiter.setChecked(false);
			edit_Limiter.setEnabled(false);		
			return true;
			// setVale
		}
		
		if (sndStatus.bDrcEnable== 1) {
			switch_Limiter.setChecked(true);
			edit_Limiter.setEnabled(true);

		try {
			//less of MTK
//			mTvMiscManager.SetLimiterThreshold(true,
//					Integer.parseInt(valueLimiterThreshold[1]
//							.replaceFirst("0x(.*)", "$1"), 16));

//			TVManager
//					.getInstance(AQService.this)
//					.getSoundManager()
//					.DspCmdSetLimiterThreshold(
//							Integer.parseInt(valueLimiterThreshold[0]
//									.replaceFirst("0x(.*)", "$1"), 16));

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		}
		TextView_Limiter.setVisibility(View.GONE);	
		switch_Limiter.setVisibility(View.GONE);
		
//		strTemp = Integer.toString(Integer.parseInt(
//				valueAUDIO_NR_THR[0].replaceFirst("0x(.*)", "$1"), 16));
		short threshold = MtkTvFApiAudio.getInstance().getAudioIniNrThreshold(curAudioSource);
		edit_NRThreshold.setText(threshold+"");

		try {
			
			MtkTvFApiAudio.getInstance().setNrThreshold(curAudioSource, threshold);
			
//			 mTvMiscManager.SetSndNrThreshold(Integer.parseInt(valueAUDIO_NR_THR[0].replaceFirst(
//								"0x(.*)", "$1"), 16));

//			TVManager
//					.getInstance(AQService.this)
//					.getSoundManager()
//					.DspCmdSetSndNrThreshold(
//							Integer.parseInt(valueAUDIO_NR_THR[0].replaceFirst(
//									"0x(.*)", "$1"), 16));

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		// setvalue()

		PEQ1[1] = MtkTvFApiAudio.getInstance().getPeqFoCoarse(EnumSoundMode.values()[SOUND_MODE_ID],(short)PEQ1[0]);
		PEQ1[2] = MtkTvFApiAudio.getInstance().getPeqFoFine(EnumSoundMode.values()[SOUND_MODE_ID],(short)PEQ1[0]);
		PEQ1[3] = MtkTvFApiAudio.getInstance().getPeqQ(EnumSoundMode.values()[SOUND_MODE_ID],(short)PEQ1[0]);
		PEQ1[4] = MtkTvFApiAudio.getInstance().getPeqGain(EnumSoundMode.values()[SOUND_MODE_ID],(short)PEQ1[0]);
		PEQ2[1] = MtkTvFApiAudio.getInstance().getPeqFoCoarse(EnumSoundMode.values()[SOUND_MODE_ID],(short)PEQ2[0]);
		PEQ2[2] = MtkTvFApiAudio.getInstance().getPeqFoFine(EnumSoundMode.values()[SOUND_MODE_ID],(short)PEQ2[0]);
		PEQ2[3] = MtkTvFApiAudio.getInstance().getPeqQ(EnumSoundMode.values()[SOUND_MODE_ID],(short)PEQ2[0]);
		PEQ2[4] = MtkTvFApiAudio.getInstance().getPeqGain(EnumSoundMode.values()[SOUND_MODE_ID],(short)PEQ2[0]);
		PEQ3[1] = MtkTvFApiAudio.getInstance().getPeqFoCoarse(EnumSoundMode.values()[SOUND_MODE_ID],(short)PEQ3[0]);
		PEQ3[2] = MtkTvFApiAudio.getInstance().getPeqFoFine(EnumSoundMode.values()[SOUND_MODE_ID],(short)PEQ3[0]);
		PEQ3[3] = MtkTvFApiAudio.getInstance().getPeqQ(EnumSoundMode.values()[SOUND_MODE_ID],(short)PEQ3[0]);
		PEQ3[4] = MtkTvFApiAudio.getInstance().getPeqGain(EnumSoundMode.values()[SOUND_MODE_ID],(short)PEQ3[0]);
		
		
		return true;

	}

	public boolean saveChangeOtherValue(int value_ID, View view, boolean isFocus) {
		Log.v("lhtest","saveChangeOtherValue");
		EditText clickEditText = (EditText) view;
		// clickEditText.setTextColor(Color.WHITE);
		String text = clickEditText.getText().toString().trim();
		try {
			if (isFocus)// focus
			{
				if (switchFocus) {
					focusEditText = clickEditText;
				} else {
					focusEditText.requestFocus();
					return false;
				}
				prevStr = text;
				// clickEditText.setInputType(InputType.TYPE_NULL);
				// clickEditText.setTextColor(Color.BLACK);
				clickEditText.selectAll();
				if (value_ID > 1) {
					Drawable draw = getResources().getDrawable(
							android.R.drawable.stat_sys_download);
					draw.setBounds(0, 0, 30, 30); // You must set the size, otherwise it will not display
					clickEditText.setError(
							"0x" + Integer.toHexString(Integer.parseInt(text)),
							draw);
				}

			} else {
				// Get current text
				switch (value_ID) {
				case 0:
					break;
				case 1:
					if ("".equals(text)) {
						clickEditText.setText(prevStr);
						return true;
					}
					valueIniVersion[1] = text;
					Log.v(TAG, text);

					break;
				case 2:
					Log.v("lhtest","saveChangeOtherValue case 2");
					if ("".equals(text)) {
						clickEditText.setText(prevStr);
						switchFocus = true;
						return true;
					}
					int outGainValue = 0;
					try {
						outGainValue = Integer.parseInt(text);
					} catch (Exception e) {
						e.printStackTrace();
						outGainValue = 0;
						switchFocus = false;
						focusEditText = clickEditText;
						Toast.makeText(AQService.this, "Please enter the correct value",
								Toast.LENGTH_LONG).show();
						return false;
					}
					if (outGainValue < 0 || outGainValue > 0x7fffff) {
						OpenTipDialog("warning", "The value entered is out of range!");
						switchFocus = false;
						focusEditText = clickEditText;

						return false;
					}
					// setvalue(outGainValue);
					if (focusEditText == clickEditText) {
						switchFocus = true;
					}

					String strTemp = Integer.toHexString(outGainValue);
					valueLimiterThreshold[1] = "0x" + strTemp;
					Log.v(TAG, strTemp);
					Log.v("lhtest","saveChangeOtherValue strTemp="+strTemp+" outGainValue="+outGainValue);

					try {
						saveDrcLimiterToAllSource(outGainValue);
						//less of MTK
//						mTvMiscManager.SetLimiterThreshold(true,outGainValue);

//						TVManager.getInstance(AQService.this).getSoundManager()
//								.DspCmdSetLimiterThreshold(outGainValue);

					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					break;

				case 3:
					if ("".equals(text)) {
						clickEditText.setText(prevStr);
						switchFocus = true;
						return true;
					}
					int NRValue = 0;
					try {
						NRValue = Integer.parseInt(text);
					} catch (Exception e) {
						e.printStackTrace();
						NRValue = 0;
						switchFocus = false;
						focusEditText = clickEditText;
						Toast.makeText(AQService.this, "Please enter the correct value",
								Toast.LENGTH_LONG).show();
						return false;
					}
					if (NRValue < 0 || NRValue > 0xff) {
						OpenTipDialog("warning", "The value entered is out of range!");
						/*
						 * clickEditText.setText(valueAUDIO_NR_THR[0].toString())
						 * ; try {
						 * 
						 * TVManager .getInstance(AQService.this)
						 * .getSoundManager() .DspCmdSetSndNrThreshold(
						 * Integer.parseInt( valueAUDIO_NR_THR[0] .replaceFirst(
						 * "0x(.*)", "$1"), 16));
						 * 
						 * } catch (TVManagerNotInitException e) { // TODO
						 * Auto-generated catch block e.printStackTrace(); }
						 */
						switchFocus = false;
						focusEditText = clickEditText;
						return false;
					}
					// setvalue(outGainValue);
					if (focusEditText == clickEditText) {
						switchFocus = true;
					}

					String Temp = Integer.toHexString(NRValue);
					valueAUDIO_NR_THR[0] = "0x" + Temp;
					Log.v(TAG, Temp);

					try {
						String platform=SystemProperties.get("ro.board.platform", "");
						AudioInputSource currentAudioSource = MtkTvFApiAudio.getInstance().getCurrentAudioSrc();
						if(platform.equals("m5621") || platform.equals("m7322")) {
							MtkTvFApiAudio.getInstance().setNrThreshold(EnumSoundMode.values()[SOUND_MODE_ID],(short)NRValue);
						}else {
							MtkTvFApiAudio.getInstance().setNrThreshold(currentAudioSource,(short)NRValue);
						}

						
						
//						TVManager.getInstance(AQService.this).getSoundManager()
//								.DspCmdSetSndNrThreshold(NRValue);

					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}

					break;
				default:
					break;
				}
			}

		} catch (Exception e) {

			e.printStackTrace();
			return false;

		}

		return true;
	}
	
	private void refreshViewsOnPeqPeq(){
		int peqEnable = MtkTvFApiAudio.getInstance().getPEQEnable(EnumSoundMode.values()[SOUND_MODE_ID],(short)0);
		if(peqEnable == 1) {
			switch_peq_PEQ.setChecked(true);
			setPEQPEQEnable(true);	
		}else {
			switch_peq_PEQ.setChecked(false);
			setPEQPEQEnable(false);
		}
		
		
		int peqfre = MtkTvFApiAudio.getInstance().getPeqFreq(EnumSoundMode.values()[SOUND_MODE_ID],(short)0);
		int peqeqvalue = MtkTvFApiAudio.getInstance().getPeqQ(EnumSoundMode.values()[SOUND_MODE_ID],(short)0);
		int peqgain = MtkTvFApiAudio.getInstance().getPeqGain(EnumSoundMode.values()[SOUND_MODE_ID],(short)0);
		edit_fre_band1.setText(peqfre+"");
		edit_eqvalue_band1.setText(peqeqvalue+"");
		seekBar_peqgain_band1.setProgress(peqgain/5);
		TextView_peqgain_band1.setText(peqgain+"");
		
		peqfre = MtkTvFApiAudio.getInstance().getPeqFreq(EnumSoundMode.values()[SOUND_MODE_ID],(short)1);
		peqeqvalue = MtkTvFApiAudio.getInstance().getPeqQ(EnumSoundMode.values()[SOUND_MODE_ID],(short)1);
		peqgain = MtkTvFApiAudio.getInstance().getPeqGain(EnumSoundMode.values()[SOUND_MODE_ID],(short)1);
		edit_fre_band2.setText(peqfre+"");
		edit_eqvalue_band2.setText(peqeqvalue+"");
		seekBar_peqgain_band2.setProgress(peqgain/5);
		TextView_peqgain_band2.setText(peqgain+"");
		
		peqfre = MtkTvFApiAudio.getInstance().getPeqFreq(EnumSoundMode.values()[SOUND_MODE_ID],(short)2);
		peqeqvalue = MtkTvFApiAudio.getInstance().getPeqQ(EnumSoundMode.values()[SOUND_MODE_ID],(short)2);
		peqgain = MtkTvFApiAudio.getInstance().getPeqGain(EnumSoundMode.values()[SOUND_MODE_ID],(short)2);
		edit_fre_band3.setText(peqfre+"");
		edit_eqvalue_band3.setText(peqeqvalue+"");
		seekBar_peqgain_band3.setProgress(peqgain/5);
		TextView_peqgain_band3.setText(peqgain+"");
		
		peqfre = MtkTvFApiAudio.getInstance().getPeqFreq(EnumSoundMode.values()[SOUND_MODE_ID],(short)3);
		peqeqvalue = MtkTvFApiAudio.getInstance().getPeqQ(EnumSoundMode.values()[SOUND_MODE_ID],(short)3);
		peqgain = MtkTvFApiAudio.getInstance().getPeqGain(EnumSoundMode.values()[SOUND_MODE_ID],(short)3);
		edit_fre_band4.setText(peqfre+"");
		edit_eqvalue_band4.setText(peqeqvalue+"");
		seekBar_peqgain_band4.setProgress(peqgain/5);
		TextView_peqgain_band4.setText(peqgain+"");
		
		peqfre = MtkTvFApiAudio.getInstance().getPeqFreq(EnumSoundMode.values()[SOUND_MODE_ID],(short)4);
		peqeqvalue = MtkTvFApiAudio.getInstance().getPeqQ(EnumSoundMode.values()[SOUND_MODE_ID],(short)4);
		peqgain = MtkTvFApiAudio.getInstance().getPeqGain(EnumSoundMode.values()[SOUND_MODE_ID],(short)4);
		edit_fre_band5.setText(peqfre+"");
		edit_eqvalue_band5.setText(peqeqvalue+"");
		seekBar_peqgain_band5.setProgress(peqgain/5);
		TextView_peqgain_band5.setText(peqgain+"");
		
		peqfre = MtkTvFApiAudio.getInstance().getPeqFreq(EnumSoundMode.values()[SOUND_MODE_ID],(short)5);
		peqeqvalue = MtkTvFApiAudio.getInstance().getPeqQ(EnumSoundMode.values()[SOUND_MODE_ID],(short)5);
		peqgain = MtkTvFApiAudio.getInstance().getPeqGain(EnumSoundMode.values()[SOUND_MODE_ID],(short)5);
		edit_fre_band6.setText(peqfre+"");
		edit_eqvalue_band6.setText(peqeqvalue+"");
		seekBar_peqgain_band6.setProgress(peqgain/5);
		TextView_peqgain_band6.setText(peqgain+"");
		
		peqfre = MtkTvFApiAudio.getInstance().getPeqFreq(EnumSoundMode.values()[SOUND_MODE_ID],(short)6);
		peqeqvalue = MtkTvFApiAudio.getInstance().getPeqQ(EnumSoundMode.values()[SOUND_MODE_ID],(short)6);
		peqgain = MtkTvFApiAudio.getInstance().getPeqGain(EnumSoundMode.values()[SOUND_MODE_ID],(short)6);
		edit_fre_band7.setText(peqfre+"");
		edit_eqvalue_band7.setText(peqeqvalue+"");
		seekBar_peqgain_band7.setProgress(peqgain/5);
		TextView_peqgain_band7.setText(peqgain+"");
		
		peqfre = MtkTvFApiAudio.getInstance().getPeqFreq(EnumSoundMode.values()[SOUND_MODE_ID],(short)7);
		peqeqvalue = MtkTvFApiAudio.getInstance().getPeqQ(EnumSoundMode.values()[SOUND_MODE_ID],(short)7);
		peqgain = MtkTvFApiAudio.getInstance().getPeqGain(EnumSoundMode.values()[SOUND_MODE_ID],(short)7);
		edit_fre_band8.setText(peqfre+"");
		edit_eqvalue_band8.setText(peqeqvalue+"");
		seekBar_peqgain_band8.setProgress(peqgain/5);
		TextView_peqgain_band8.setText(peqgain+"");
		
		peqfre = MtkTvFApiAudio.getInstance().getPeqFreq(EnumSoundMode.values()[SOUND_MODE_ID],(short)8);
		peqeqvalue = MtkTvFApiAudio.getInstance().getPeqQ(EnumSoundMode.values()[SOUND_MODE_ID],(short)8);
		peqgain = MtkTvFApiAudio.getInstance().getPeqGain(EnumSoundMode.values()[SOUND_MODE_ID],(short)8);
		edit_fre_band9.setText(peqfre+"");
		edit_eqvalue_band9.setText(peqeqvalue+"");
		seekBar_peqgain_band9.setProgress(peqgain/5);
		TextView_peqgain_band9.setText(peqgain+"");
		
		peqfre = MtkTvFApiAudio.getInstance().getPeqFreq(EnumSoundMode.values()[SOUND_MODE_ID],(short)9);
		peqeqvalue = MtkTvFApiAudio.getInstance().getPeqQ(EnumSoundMode.values()[SOUND_MODE_ID],(short)9);
		peqgain = MtkTvFApiAudio.getInstance().getPeqGain(EnumSoundMode.values()[SOUND_MODE_ID],(short)9);
		edit_fre_band10.setText(peqfre+"");
		edit_eqvalue_band10.setText(peqeqvalue+"");
		seekBar_peqgain_band10.setProgress(peqgain/5);
		TextView_peqgain_band10.setText(peqgain+"");
		
		peqfre = MtkTvFApiAudio.getInstance().getPeqFreq(EnumSoundMode.values()[SOUND_MODE_ID],(short)10);
		peqeqvalue = MtkTvFApiAudio.getInstance().getPeqQ(EnumSoundMode.values()[SOUND_MODE_ID],(short)10);
		peqgain = MtkTvFApiAudio.getInstance().getPeqGain(EnumSoundMode.values()[SOUND_MODE_ID],(short)10);
		edit_fre_band11.setText(peqfre+"");
		edit_eqvalue_band11.setText(peqeqvalue+"");
		seekBar_peqgain_band11.setProgress(peqgain/5);
		TextView_peqgain_band11.setText(peqgain+"");
		
		peqfre = MtkTvFApiAudio.getInstance().getPeqFreq(EnumSoundMode.values()[SOUND_MODE_ID],(short)11);
		peqeqvalue = MtkTvFApiAudio.getInstance().getPeqQ(EnumSoundMode.values()[SOUND_MODE_ID],(short)11);
		peqgain = MtkTvFApiAudio.getInstance().getPeqGain(EnumSoundMode.values()[SOUND_MODE_ID],(short)11);
		edit_fre_band12.setText(peqfre+"");
		edit_eqvalue_band12.setText(peqeqvalue+"");
		seekBar_peqgain_band12.setProgress(peqgain/5);
		TextView_peqgain_band12.setText(peqgain+"");
		
		peqfre = MtkTvFApiAudio.getInstance().getPeqFreq(EnumSoundMode.values()[SOUND_MODE_ID],(short)12);
		peqeqvalue = MtkTvFApiAudio.getInstance().getPeqQ(EnumSoundMode.values()[SOUND_MODE_ID],(short)12);
		peqgain = MtkTvFApiAudio.getInstance().getPeqGain(EnumSoundMode.values()[SOUND_MODE_ID],(short)12);
		edit_fre_band13.setText(peqfre+"");
		edit_eqvalue_band13.setText(peqeqvalue+"");
		seekBar_peqgain_band13.setProgress(peqgain/5);
		TextView_peqgain_band13.setText(peqgain+"");
		


	}
	
	private void refreshViewsOnPeq(int bandNum){
		PEQ1[1] = MtkTvFApiAudio.getInstance().getPeqFoCoarse(EnumSoundMode.values()[SOUND_MODE_ID],(short)peqBandNum);
		PEQ1[2] = MtkTvFApiAudio.getInstance().getPeqFoFine(EnumSoundMode.values()[SOUND_MODE_ID],(short)peqBandNum);
		PEQ1[3] = MtkTvFApiAudio.getInstance().getPeqQ(EnumSoundMode.values()[SOUND_MODE_ID],(short)peqBandNum);
		PEQ1[4] = MtkTvFApiAudio.getInstance().getPeqGain(EnumSoundMode.values()[SOUND_MODE_ID],(short)peqBandNum);
		edit_PEQFrequenceH_1.setText(PEQ1[1]+"");//singleValue[1].trim());
		edit_PEQFrequenceL_1.setText(PEQ1[2]+"");
		edit_EQ_Value_1.setText(PEQ1[3]+"");
		edit_PEQGain_1.setText(PEQ1[4]+"");
	}

	public OnFocusChangeListener focusChangeListener_AQID = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			((EditText) view).setTextColor(Color.WHITE);
			saveChangeOtherValue(0, view, isFocus);
		}

	};

	public OnFocusChangeListener focusChangeListener_Version = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			// ((EditText) view).setTextColor(Color.WHITE);
			saveChangeOtherValue(1, view, isFocus);
		}

	};
	public OnFocusChangeListener focusChangeListener_Limiter = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			// ((EditText) view).setTextColor(Color.WHITE);
			saveChangeOtherValue(2, view, isFocus);
		}

	};
	public OnFocusChangeListener focusChangeListener_NRThreshold = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			// ((EditText) view).setTextColor(Color.WHITE);
			saveChangeOtherValue(3, view, isFocus);
		}

	};

	// =============
	public OnKeyListener keyListener_AQID = new OnKeyListener() {

		public boolean onKey(View view, int keycode, KeyEvent event) {

			EditText clickEditText = (EditText) view;

			EditTextInputErrorTip(clickEditText, 4, true);

			return false;

		}
	};

	public OnKeyListener keyListener_Version = new OnKeyListener() {

		public boolean onKey(View view, int keycode, KeyEvent event) {

			EditText clickEditText = (EditText) view;

			EditTextInputErrorTip(clickEditText, 8, false);

			return false;

		}
	};

	public OnKeyListener keyListener_Limiter = new OnKeyListener() {

		public boolean onKey(View view, int keycode, KeyEvent event) {

			EditText clickEditText = (EditText) view;

			EditTextInputErrorTip(clickEditText, 10, true);

			return false;

		}
	};

	public OnKeyListener keyListener_NRThreshold = new OnKeyListener() {

		public boolean onKey(View view, int keycode, KeyEvent event) {

			EditText clickEditText = (EditText) view;

			EditTextInputErrorTip(clickEditText, 3, true);

			return false;

		}
	};
	
	public OnKeyListener keyListener_seerbar_PEQGAIN = new OnKeyListener() {

		public boolean onKey(View view, int keycode, KeyEvent event) {

			if (event.getAction() == KeyEvent.ACTION_DOWN) {
				if(keycode == KeyEvent.KEYCODE_DPAD_CENTER) {
					if(seekBar_peqgain_band1.hasFocus()) {
						edit_fre_band2.requestFocus();
					}else if(seekBar_peqgain_band2.hasFocus()) {
						edit_fre_band3.requestFocus();
					}else if(seekBar_peqgain_band3.hasFocus()) {
						edit_fre_band4.requestFocus();
					}else if(seekBar_peqgain_band4.hasFocus()) {
						edit_fre_band5.requestFocus();
					}else if(seekBar_peqgain_band5.hasFocus()) {
						edit_fre_band6.requestFocus();
					}else if(seekBar_peqgain_band6.hasFocus()) {
						edit_fre_band7.requestFocus();
					}else if(seekBar_peqgain_band7.hasFocus()) {
						edit_fre_band8.requestFocus();
					}else if(seekBar_peqgain_band8.hasFocus()) {
						edit_fre_band9.requestFocus();
					}else if(seekBar_peqgain_band9.hasFocus()) {
						edit_fre_band10.requestFocus();
					}else if(seekBar_peqgain_band10.hasFocus()) {
						edit_fre_band11.requestFocus();
					}else if(seekBar_peqgain_band11.hasFocus()) {
						edit_fre_band12.requestFocus();
					}else if(seekBar_peqgain_band12.hasFocus()) {
						edit_fre_band13.requestFocus();
					}else if(seekBar_peqgain_band13.hasFocus()) {
						edit_fre_band1.requestFocus();
					}
					return true;
				}
				return false;
			}

			return false;

		}
	};

	// switch control

	Switch switch_PEQ;
	EditText edit_PEQBand_1, edit_PEQBand_2, edit_PEQBand_3,
			edit_PEQFrequenceH_1, edit_PEQFrequenceH_2, edit_PEQFrequenceH_3,
			edit_PEQFrequenceL_1, edit_PEQFrequenceL_2, edit_PEQFrequenceL_3,
			edit_EQ_Value_1, edit_EQ_Value_2, edit_EQ_Value_3, edit_PEQGain_1,
			edit_PEQGain_2, edit_PEQGain_3;
	
	Switch switch_GEQ;
	EditText edit_GEQ1, edit_GEQ2, edit_GEQ3, edit_GEQ4, edit_GEQ5;
    
	
	public boolean setAndDisplayPEQStatus() {
		HPF_Gain.setText(HPF[0]+"");
		HPF_Fre.setText(HPF[1]+"");
		HPF_QValue.setText(HPF[2]+"");
		BasicSoundEnableStatus sndStatus = new BasicSoundEnableStatus();
		MtkTvFApiAudio.getInstance().getBasicSoundEnableStatus(EnumSoundMode.values()[SOUND_MODE_ID], sndStatus);
		if(sndStatus.bHpfEnable == 1){
			switch_hpf.setChecked(true);
			HPF_Gain.setEnabled(true);
			HPF_Fre.setEnabled(true);
			HPF_QValue.setEnabled(true);

		}else {
			switch_hpf.setChecked(false);
			HPF_Gain.setEnabled(false);
			HPF_Fre.setEnabled(false);
			HPF_QValue.setEnabled(false);
		}
		
		
//		int peqEnable = MtkTvFApiAudio.getInstance().getPEQEnable(EnumSoundMode.values()[SOUND_MODE_ID],(short)0);
//		if (peqEnable == 0) {
//			switch_PEQ.setChecked(false);
//			setPEQEnable(false);
//			return true;
//			// setVale
//		}
//
//		if (peqEnable == 1) {
//			switch_PEQ.setChecked(true);
//			setPEQEnable(true);
//			// setValue
//		}
//		
//		switch_GEQ.setChecked(true);
//
//
//
//		edit_PEQBand_1.setText(PEQ1[0]+"");
//		edit_PEQBand_2.setText(PEQ2[0]+"");
//		edit_PEQBand_3.setText(PEQ3[0]+"");
//		edit_PEQFrequenceH_1.setText(PEQ1[1]+"");//singleValue[1].trim());
//		edit_PEQFrequenceH_2.setText(PEQ2[1]+"");
//		edit_PEQFrequenceH_3.setText(PEQ3[1]+"");
//		edit_PEQFrequenceL_1.setText(PEQ1[2]+"");
//		edit_PEQFrequenceL_2.setText(PEQ2[2]+"");
//		edit_PEQFrequenceL_3.setText(PEQ3[2]+"");
//		edit_EQ_Value_1.setText(PEQ1[3]+"");
//		edit_EQ_Value_2.setText(PEQ2[3]+"");
//		edit_EQ_Value_3.setText(PEQ3[3]+"");
//		edit_PEQGain_1.setText(PEQ1[4]+"");
//		edit_PEQGain_2.setText(PEQ2[4]+"");
//		edit_PEQGain_3.setText(PEQ3[4]+"");
		
		Log.v("lhtest","setAndDisplayPEQStatus argSoundEffect geqGain[0]="+GEQ[0]
				+" geqGain[1]="+GEQ[1]+" geqGain[2]="+GEQ[2]+" geqGain[3]="+GEQ[3]
						+" geqGain[4]="+GEQ[4]);
		
		edit_GEQ1.setText(GEQ[0]+"");
		edit_GEQ2.setText(GEQ[1]+"");
		edit_GEQ3.setText(GEQ[2]+"");
		edit_GEQ4.setText(GEQ[3]+"");
		edit_GEQ5.setText(GEQ[4]+"");

		// setvalue 0~5

		return true;
	}
	
	public void setHPFEnable(boolean enabled) {


		HPF_Gain.setEnabled(enabled);
		HPF_Fre.setEnabled(enabled);
		HPF_QValue.setEnabled(enabled);

        
		HPF_Gain.setFocusable(enabled);
		HPF_Fre.setFocusable(enabled);
		HPF_QValue.setFocusable(enabled);

		try {
			BasicSoundEnableStatus sndStatus = new BasicSoundEnableStatus();
			MtkTvFApiAudio.getInstance().getBasicSoundEnableStatus(EnumSoundMode.values()[SOUND_MODE_ID], sndStatus);
			if(enabled){
					sndStatus.bHpfEnable = 1;
			} else {
					sndStatus.bHpfEnable = 0;
			}
			MtkTvFApiAudio.getInstance().enableBasicSoundEffect(EnumSoundMode.values()[SOUND_MODE_ID], sndStatus);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
	
	public void setPEQPEQEnable(boolean enabled) {

        edit_fre_band1.setEnabled(enabled);
        edit_fre_band2.setEnabled(enabled);
        edit_fre_band3.setEnabled(enabled);
        edit_fre_band4.setEnabled(enabled);
        edit_fre_band5.setEnabled(enabled);
        edit_fre_band6.setEnabled(enabled);
        edit_fre_band7.setEnabled(enabled);
        edit_fre_band8.setEnabled(enabled);
        edit_fre_band9.setEnabled(enabled);
        edit_fre_band10.setEnabled(enabled);
        edit_fre_band11.setEnabled(enabled);
        edit_fre_band12.setEnabled(enabled);
        edit_fre_band13.setEnabled(enabled);
        edit_eqvalue_band1.setEnabled(enabled);
        edit_eqvalue_band2.setEnabled(enabled);
        edit_eqvalue_band3.setEnabled(enabled);
        edit_eqvalue_band4.setEnabled(enabled);
        edit_eqvalue_band5.setEnabled(enabled);
        edit_eqvalue_band6.setEnabled(enabled);
        edit_eqvalue_band7.setEnabled(enabled);
        edit_eqvalue_band8.setEnabled(enabled);
        edit_eqvalue_band9.setEnabled(enabled);
        edit_eqvalue_band10.setEnabled(enabled);
        edit_eqvalue_band11.setEnabled(enabled);
        edit_eqvalue_band12.setEnabled(enabled);
        edit_eqvalue_band13.setEnabled(enabled);
        seekBar_peqgain_band1.setEnabled(enabled);
        seekBar_peqgain_band2.setEnabled(enabled);
        seekBar_peqgain_band3.setEnabled(enabled);
        seekBar_peqgain_band4.setEnabled(enabled);
        seekBar_peqgain_band5.setEnabled(enabled);
        seekBar_peqgain_band6.setEnabled(enabled);
        seekBar_peqgain_band7.setEnabled(enabled);
        seekBar_peqgain_band8.setEnabled(enabled);
        seekBar_peqgain_band9.setEnabled(enabled);
        seekBar_peqgain_band10.setEnabled(enabled);
        seekBar_peqgain_band11.setEnabled(enabled);
        seekBar_peqgain_band12.setEnabled(enabled);
        seekBar_peqgain_band13.setEnabled(enabled);
        
        edit_fre_band1.setFocusable(enabled);
        edit_fre_band2.setFocusable(enabled);
        edit_fre_band3.setFocusable(enabled);
        edit_fre_band4.setFocusable(enabled);
        edit_fre_band5.setFocusable(enabled);
        edit_fre_band6.setFocusable(enabled);
        edit_fre_band7.setFocusable(enabled);
        edit_fre_band8.setFocusable(enabled);
        edit_fre_band9.setFocusable(enabled);
        edit_fre_band10.setFocusable(enabled);
        edit_fre_band11.setFocusable(enabled);
        edit_fre_band12.setFocusable(enabled);
        edit_fre_band13.setFocusable(enabled);
        edit_eqvalue_band1.setFocusable(enabled);
        edit_eqvalue_band2.setFocusable(enabled);
        edit_eqvalue_band3.setFocusable(enabled);
        edit_eqvalue_band4.setFocusable(enabled);
        edit_eqvalue_band5.setFocusable(enabled);
        edit_eqvalue_band6.setFocusable(enabled);
        edit_eqvalue_band7.setFocusable(enabled);
        edit_eqvalue_band8.setFocusable(enabled);
        edit_eqvalue_band9.setFocusable(enabled);
        edit_eqvalue_band10.setFocusable(enabled);
        edit_eqvalue_band11.setFocusable(enabled);
        edit_eqvalue_band12.setFocusable(enabled);
        edit_eqvalue_band13.setFocusable(enabled);
        seekBar_peqgain_band1.setFocusable(enabled);
        seekBar_peqgain_band2.setFocusable(enabled);
        seekBar_peqgain_band3.setFocusable(enabled);
        seekBar_peqgain_band4.setFocusable(enabled);
        seekBar_peqgain_band5.setFocusable(enabled);
        seekBar_peqgain_band6.setFocusable(enabled);
        seekBar_peqgain_band7.setFocusable(enabled);
        seekBar_peqgain_band8.setFocusable(enabled);
        seekBar_peqgain_band9.setFocusable(enabled);
        seekBar_peqgain_band10.setFocusable(enabled);
        seekBar_peqgain_band11.setFocusable(enabled);
        seekBar_peqgain_band12.setFocusable(enabled);
        seekBar_peqgain_band13.setFocusable(enabled);
        
		


		try {
			for(int i = 0; i< 3; i++){//SoundEffectParams.PEQ_MAX_BANDS; i++){
				MtkTvFApiAudio.getInstance().setPEQEnable(EnumSoundMode.values()[SOUND_MODE_ID],(short) i, enabled);
			}
			MtkTvFApiAudio.getInstance().saveAudioIni();
			
//            mTvMiscManager.DspCmdSetPEQEnable(enabled);
//			TVManager.getInstance(AQService.this).getSoundManager()
//					.DspCmdSetPEQEnable(enabled);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	public void setPEQEnable(boolean enabled) {
		edit_PEQBand_1.setEnabled(enabled);
		edit_PEQBand_2.setEnabled(enabled);
		edit_PEQBand_3.setEnabled(enabled);
		edit_PEQFrequenceH_1.setEnabled(enabled);
		edit_PEQFrequenceH_2.setEnabled(enabled);
		edit_PEQFrequenceH_3.setEnabled(enabled);
		edit_PEQFrequenceL_1.setEnabled(enabled);
		edit_PEQFrequenceL_2.setEnabled(enabled);
		edit_PEQFrequenceL_3.setEnabled(enabled);
		edit_EQ_Value_1.setEnabled(enabled);
		edit_EQ_Value_2.setEnabled(enabled);
		edit_EQ_Value_3.setEnabled(enabled);
		edit_PEQGain_1.setEnabled(enabled);
		edit_PEQGain_2.setEnabled(enabled);
		edit_PEQGain_3.setEnabled(enabled);

		edit_PEQBand_1.setFocusable(enabled);
		edit_PEQBand_2.setFocusable(enabled);
		edit_PEQBand_3.setFocusable(enabled);
		edit_PEQFrequenceH_1.setFocusable(enabled);
		edit_PEQFrequenceH_2.setFocusable(enabled);
		edit_PEQFrequenceH_3.setFocusable(enabled);
		edit_PEQFrequenceL_1.setFocusable(enabled);
		edit_PEQFrequenceL_2.setFocusable(enabled);
		edit_PEQFrequenceL_3.setFocusable(enabled);
		edit_EQ_Value_1.setFocusable(enabled);
		edit_EQ_Value_2.setFocusable(enabled);
		edit_EQ_Value_3.setFocusable(enabled);
		edit_PEQGain_1.setFocusable(enabled);
		edit_PEQGain_2.setFocusable(enabled);
		edit_PEQGain_3.setFocusable(enabled);

		try {
			for(int i = 0; i< 3; i++){//SoundEffectParams.PEQ_MAX_BANDS; i++){
				MtkTvFApiAudio.getInstance().setPEQEnable(EnumSoundMode.values()[SOUND_MODE_ID],(short) i, enabled);
			}
			MtkTvFApiAudio.getInstance().saveAudioIni();
			
//            mTvMiscManager.DspCmdSetPEQEnable(enabled);
//			TVManager.getInstance(AQService.this).getSoundManager()
//					.DspCmdSetPEQEnable(enabled);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
	public void setGEQEnable(boolean enabled) {

		edit_GEQ1.setEnabled(enabled);
		edit_GEQ2.setEnabled(enabled);
		edit_GEQ3.setEnabled(enabled);
		edit_GEQ4.setEnabled(enabled);
		edit_GEQ5.setEnabled(enabled);


		edit_GEQ1.setFocusable(enabled);
		edit_GEQ2.setFocusable(enabled);
		edit_GEQ3.setFocusable(enabled);
		edit_GEQ4.setFocusable(enabled);
		edit_GEQ5.setFocusable(enabled);


//		try {
//			for(int i = 0; i< 3; i++){//SoundEffectParams.PEQ_MAX_BANDS; i++){
//				MtkTvFApiAudio.getInstance().setPEQEnable(EnumSoundMode.values()[SOUND_MODE_ID],(short) i, enabled);
//			}
//			MtkTvFApiAudio.getInstance().saveAudioIni();
//			
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}

	}


	public boolean saveChangePEQValue(int view_ID, View view, boolean isFocus) {
		if (view_ID == 0) {
//			if (isFocus) {
//				valuePEQ_PARAM[0] = "TRUE";
//			} else {
//				valuePEQ_PARAM[0] = "FALSE";
//			}
//			Log.v(TAG, valuePEQ_PARAM[0]);
//			setPEQEnable(isChecked);
			return true;
		}

		if (view_ID > 0 && view_ID < 50) {

			EditText clickEditText = (EditText) view;
			String text = clickEditText.getText().toString().trim();
			try {
				if (isFocus)// focus
				{
					if (switchFocus) {
						focusEditText = clickEditText;
					} else {
						focusEditText.requestFocus();
						return false;
					}
					// clickEditText.setInputType(InputType.TYPE_NULL);
					prevStr = text;
					// clickEditText.setTextColor(Color.BLACK);
					clickEditText.selectAll();

					// Drawable draw =
					// getResources().getDrawable(android.R.drawable.stat_sys_download);
					// draw.setBounds(0, 0, 30, 30); //You must set the size, otherwise it will not display
					// clickEditText.setError("0x"+Integer.toHexString(Integer.parseInt(text)),draw);
				} else {
					// Get current text
					// clickEditText.setTextColor(Color.BLACK);

					if ("".equals(text)) {
						clickEditText.setText(prevStr);
						switchFocus = true;
						return true;
					}
					int outGainValue = 0;
					try {
						outGainValue = Integer.parseInt(text);
					} catch (Exception e) {
						e.printStackTrace();
						outGainValue = 0;
						switchFocus = false;
						focusEditText = clickEditText;
						Toast.makeText(AQService.this, "Please enter the correct value",
								Toast.LENGTH_LONG).show();
						return false;
					}

					if (!checkOthersValue(view_ID, outGainValue)) {
						OpenTipDialog("warning", "The value entered is out of range!");
						switchFocus = false;
						focusEditText = clickEditText;
						return false;
					}
					// setvalue(outGainValue);
					if (focusEditText == clickEditText) {
						switchFocus = true;
					}

//					String stringTemp1 = valuePEQ_PARAM[1];
//					String strArrayValue1 = stringTemp1.trim();
//					if (strArrayValue1.matches("\\{.*\\}")) {
//						stringTemp1 = strArrayValue1.replaceFirst("\\{(.*)\\}",
//								"$1");
//					} else {
//						OpenTipDialog(getString(R.string.pq_warning), getString(R.string.aq_data_format_error));
//						return false;
//					}
//					Log.v(TAG, stringTemp1);
//					String[] singleValue1 = stringTemp1.split(",");
//					if (singleValue1.length != 5) {
//						OpenTipDialog(getString(R.string.pq_warning), getString(R.string.aq_data_error));
//						return false;
//					}
//
//					String stringTemp2 = valuePEQ_PARAM[2];
//					String strArrayValue2 = stringTemp2.trim();
//					if (strArrayValue2.matches("\\{.*\\}")) {
//						stringTemp2 = strArrayValue2.replaceFirst("\\{(.*)\\}",
//								"$1");
//					} else {
//						OpenTipDialog(getString(R.string.pq_warning), getString(R.string.aq_data_format_error));
//						return false;
//					}
//					Log.v(TAG, stringTemp2);
//					String[] singleValue2 = stringTemp2.split(",");
//					if (singleValue2.length != 5) {
//						OpenTipDialog(getString(R.string.pq_warning), getString(R.string.aq_data_error));
//						return false;
//					}
//
//					String stringTemp3 = valuePEQ_PARAM[3];
//					String strArrayValue3 = stringTemp3.trim();
//					if (strArrayValue3.matches("\\{.*\\}")) {
//						stringTemp3 = strArrayValue3.replaceFirst("\\{(.*)\\}",
//								"$1");
//					} else {
//						OpenTipDialog(getString(R.string.pq_warning), getString(R.string.aq_data_format_error));
//						return false;
//					}
//					Log.v(TAG, stringTemp3);
//					String[] singleValue3 = stringTemp3.split(",");
//					if (singleValue3.length != 5) {
//						OpenTipDialog(getString(R.string.pq_warning), getString(R.string.aq_data_error));
//						return false;
//					}

					String strTemp = "";
					if (view_ID < 6) {
						PEQ1[view_ID - 1] = outGainValue;
						Log.d(TAG,"PEQ1["+(view_ID - 1)+"] =" + outGainValue);
						try {
							byte i = 0;
//							byte peqValue[] = new byte[5];
//							for (i = 0; i < 5; i++) {
//								peqValue[i] = (byte) Integer
//										.parseInt(singleValue1[i]);
//								Log.v(TAG, singleValue1[i]);
//							}
							switch (view_ID) {
							case 2:
								MtkTvFApiAudio.getInstance().setPeqFoCoarse(EnumSoundMode.values()[SOUND_MODE_ID],(short)peqBandNum, (short)PEQ1[1]);
								break;
							case 3:
								MtkTvFApiAudio.getInstance().setPeqFoFine(EnumSoundMode.values()[SOUND_MODE_ID],(short)peqBandNum, (short)PEQ1[2]);
								break;
							case 4:
								MtkTvFApiAudio.getInstance().setPeqQ(EnumSoundMode.values()[SOUND_MODE_ID],(short)peqBandNum, (short)PEQ1[3]);
								break;
							case 5:
								MtkTvFApiAudio.getInstance().setPeqGain(EnumSoundMode.values()[SOUND_MODE_ID],(short)peqBandNum, (short)PEQ1[4]);
								break;

							default:
								break;
							}
//							MtkTvFApiAudio.getInstance().setPeqFoCoarse(EnumSoundMode.values()[SOUND_MODE_ID],(short)PEQ1[0], (short)PEQ1[1]);
//							MtkTvFApiAudio.getInstance().setPeqFoFine(EnumSoundMode.values()[SOUND_MODE_ID],(short)PEQ1[0], (short)PEQ1[2]);
//							MtkTvFApiAudio.getInstance().setPeqQ(EnumSoundMode.values()[SOUND_MODE_ID],(short)PEQ1[0], (short)PEQ1[3]);
//							MtkTvFApiAudio.getInstance().setPeqGain(EnumSoundMode.values()[SOUND_MODE_ID],(short)PEQ1[0], (short)PEQ1[4]);
							Log.d(TAG,"save PEQ1 "+peqBandNum+" "+PEQ1[1]+" "+PEQ1[2]+" "+PEQ1[3]+" "+PEQ1[4]+" ");
//							mTvMiscManager.SetPEQParmCfg(peqValue[0], peqValue[1], peqValue[2],
//									peqValue[3], peqValue[4]);
//							TVManager
//									.getInstance(AQService.this)
//									.getSoundManager()
//									.DspCmdSetPEQParmCfg(peqValue[0],
//											peqValue[1], peqValue[2],
//											peqValue[3], peqValue[4]);

						} catch (Exception e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}

//						for (String str : singleValue1) {
//							strTemp += "," + str;
//						}
//						strTemp = "{" + strTemp + "}";
//						strTemp = strTemp.replace("{,", "{");
//						Log.v(TAG, strTemp);
//						valuePEQ_PARAM[1] = strTemp;
//						Log.v(TAG, valuePEQ_PARAM[1]);
						return true;
					}

					if (view_ID < 11) {
						PEQ2[view_ID - 6] = outGainValue;

						try {
//							byte i = 0;
//							byte peqValue[] = new byte[5];
//							for (i = 0; i < 5; i++) {
//								peqValue[i] = (byte) Integer
//										.parseInt(singleValue2[i]);
//								Log.v(TAG, singleValue2[i]);
//							}
							switch (view_ID) {
							case 7:
								MtkTvFApiAudio.getInstance().setPeqFoCoarse(EnumSoundMode.values()[SOUND_MODE_ID],
										(short) PEQ2[0], (short) PEQ2[1]);
								break;
							case 8:
								MtkTvFApiAudio.getInstance().setPeqFoFine(EnumSoundMode.values()[SOUND_MODE_ID],
										(short) PEQ2[0], (short) PEQ2[2]);
								break;
							case 9:
								MtkTvFApiAudio.getInstance().setPeqQ(EnumSoundMode.values()[SOUND_MODE_ID],
										(short) PEQ2[0], (short) PEQ2[3]);
								break;
							case 10:
								MtkTvFApiAudio.getInstance().setPeqGain(EnumSoundMode.values()[SOUND_MODE_ID],
										(short) PEQ2[0], (short) PEQ2[4]);
								break;
							default:
								break;
							}
//							MtkTvFApiAudio.getInstance().setPeqFoCoarse(EnumSoundMode.values()[SOUND_MODE_ID],(short)PEQ2[0], (short)PEQ2[1]);
//							MtkTvFApiAudio.getInstance().setPeqFoFine(EnumSoundMode.values()[SOUND_MODE_ID],(short)PEQ2[0], (short)PEQ2[2]);
//							MtkTvFApiAudio.getInstance().setPeqQ(EnumSoundMode.values()[SOUND_MODE_ID],(short)PEQ2[0], (short)PEQ2[3]);
//							MtkTvFApiAudio.getInstance().setPeqGain(EnumSoundMode.values()[SOUND_MODE_ID],(short)PEQ2[0], (short)PEQ2[4]);
							Log.d(TAG,"save PEQ2 "+PEQ2[0]+" "+PEQ2[1]+" "+PEQ2[2]+" "+PEQ2[3]+" "+PEQ2[4]+" ");
//							mTvMiscManager.SetPEQParmCfg(peqValue[0], peqValue[1], peqValue[2],
//									peqValue[3], peqValue[4]);
//							TVManager
//									.getInstance(AQService.this)
//									.getSoundManager()
//									.DspCmdSetPEQParmCfg(peqValue[0],
//											peqValue[1], peqValue[2],
//											peqValue[3], peqValue[4]);

						} catch (Exception e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}

//						for (String str : singleValue2) {
//							strTemp += "," + str;
//						}
//						strTemp = "{" + strTemp + "}";
//						strTemp = strTemp.replace("{,", "{");
//						Log.v(TAG, strTemp);
//						valuePEQ_PARAM[2] = strTemp;
//						Log.v(TAG, valuePEQ_PARAM[2]);
						return true;
					}

					if (view_ID < 16) {
						PEQ3[view_ID - 11] = outGainValue;
						try {
//							byte i = 0;
//							byte peqValue[] = new byte[5];
//							for (i = 0; i < 5; i++) {
//								peqValue[i] = (byte) Integer
//										.parseInt(singleValue3[i]);
//								Log.v(TAG, singleValue3[i]);
//							}
							switch (view_ID) {
							case 12:
								MtkTvFApiAudio.getInstance().setPeqFoCoarse(EnumSoundMode.values()[SOUND_MODE_ID],(short)PEQ3[0], (short)PEQ3[1]);
								break;
							case 13:
								MtkTvFApiAudio.getInstance().setPeqFoFine(EnumSoundMode.values()[SOUND_MODE_ID],(short)PEQ3[0], (short)PEQ3[2]);
								break;
							case 14:
								MtkTvFApiAudio.getInstance().setPeqQ(EnumSoundMode.values()[SOUND_MODE_ID],(short)PEQ3[0], (short)PEQ3[3]);
								break;
							case 15:
								MtkTvFApiAudio.getInstance().setPeqGain(EnumSoundMode.values()[SOUND_MODE_ID],(short)PEQ3[0],(short)PEQ3[4]);
								break;
							default :
								break;
							}
//							MtkTvFApiAudio.getInstance().setPeqFoCoarse(EnumSoundMode.values()[SOUND_MODE_ID],(short)PEQ3[0], (short)PEQ3[1]);
//							MtkTvFApiAudio.getInstance().setPeqFoFine(EnumSoundMode.values()[SOUND_MODE_ID],(short)PEQ3[0], (short)PEQ3[2]);
//							MtkTvFApiAudio.getInstance().setPeqQ(EnumSoundMode.values()[SOUND_MODE_ID],(short)PEQ3[0], (short)PEQ3[3]);
//							MtkTvFApiAudio.getInstance().setPeqGain(EnumSoundMode.values()[SOUND_MODE_ID],(short)PEQ3[0],(short)PEQ3[4]);
							Log.d(TAG,"save PEQ3 "+PEQ3[0]+" "+PEQ3[1]+" "+PEQ3[2]+" "+PEQ3[3]+" "+PEQ3[4]+" ");
//							mTvMiscManager.SetPEQParmCfg(peqValue[0], peqValue[1], peqValue[2],
//									peqValue[3], peqValue[4]);
//							TVManager
//									.getInstance(AQService.this)
//									.getSoundManager()
//									.DspCmdSetPEQParmCfg(peqValue[0],
//											peqValue[1], peqValue[2],
//											peqValue[3], peqValue[4]);

						} catch (Exception e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}

//						for (String str : singleValue3) {
//							strTemp += "," + str;
//						}
//						strTemp = "{" + strTemp + "}";
//						strTemp = strTemp.replace("{,", "{");
//						Log.v(TAG, strTemp);
//						valuePEQ_PARAM[3] = strTemp;
//						Log.v(TAG, valuePEQ_PARAM[3]);
						return true;
					}
					//GEQ
					if (view_ID < 21) {
						try {
							SoundEffectParams argSoundEffect = new SoundEffectParams();
							MtkTvFApiAudio.getInstance().getAudioIniBasicSndParams(EnumSoundMode.values()[SOUND_MODE_ID],argSoundEffect);
							
							switch (view_ID) {
							case 16:
								argSoundEffect.geqGain[0] = outGainValue;
								break;
							case 17:
								argSoundEffect.geqGain[1] = outGainValue;
								break;
							case 18:
								argSoundEffect.geqGain[2] = outGainValue;
								break;
							case 19:
								argSoundEffect.geqGain[3] = outGainValue;
								break;
							case 20:
								argSoundEffect.geqGain[4] = outGainValue;
								break;
							default :
								break;
							}
							MtkTvFApiAudio.getInstance().setBasicSoundEffect(EnumSoundMode.values()[SOUND_MODE_ID], EnumBasicSoundType.E_FAPI_AUD_BASIC_SND_DRC, argSoundEffect);

						} catch (Exception e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}

						return true;
					}
					//HPF
					if (view_ID < 24) {
						try {
							SoundEffectParams argSoundEffect = new SoundEffectParams();
							MtkTvFApiAudio.getInstance().getAudioIniBasicSndParams(EnumSoundMode.values()[SOUND_MODE_ID],argSoundEffect);
							
							switch (view_ID) {
							case 21:
								argSoundEffect.HpfGain = outGainValue;
								break;
							case 22:
								argSoundEffect.HpfFrequency = outGainValue;
								break;
							case 23:
								argSoundEffect.HpfQValue = outGainValue;
								break;
							default :
								break;
							}
							MtkTvFApiAudio.getInstance().setBasicSoundEffect(EnumSoundMode.values()[SOUND_MODE_ID], EnumBasicSoundType.E_FAPI_AUD_BASIC_SND_DRC, argSoundEffect);

						} catch (Exception e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}

						return true;
					}
					//PEQ FRE
					if (view_ID < 37) {
						int curband = view_ID - 24;
						try {

							MtkTvFApiAudio.getInstance().setPeqFreq(EnumSoundMode.values()[SOUND_MODE_ID], (short)curband, outGainValue);

						} catch (Exception e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}

						return true;
					}
					//PEQ EQVALUE
					if (view_ID < 50) {
						int curband = view_ID - 37;
						try {

							MtkTvFApiAudio.getInstance().setPeqQ(EnumSoundMode.values()[SOUND_MODE_ID],(short)curband, (short)outGainValue);

						} catch (Exception e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}

						return true;
					}

				}

			} catch (Exception e) {

				e.printStackTrace();
				return false;

			}

		}
		return true;
	}

	private boolean checkOthersValue(int view_ID, int outGainValue) {
		// TODO Auto-generated method stub
		switch (view_ID) {
		case 0:
			break;
		case 1:
		case 6:
		case 11:
			if (outGainValue >= 0 && outGainValue <= 12) {
				return true;
			}
			break;
		case 2:
		case 7:
		case 12:
			if (outGainValue >= 0 && outGainValue <= 200) {
				return true;
			}
			break;
		case 3:
		case 8:
		case 13:
			if (outGainValue >= 0 && outGainValue <= 99) {
				return true;
			}
			break;
		case 4:
		case 9:
		case 14:
			if (outGainValue >= 0 && outGainValue <= 160) {
				return true;
			}
			break;
		case 5:
		case 10:
		case 15:
			if (outGainValue >= -180 && outGainValue <= 180) {
				return true;
			}
			break;
		case 16:
		case 17:
		case 18:
		case 19:
		case 20:
			if (outGainValue >= 0 && outGainValue <= 100) {
				return true;
			}
			break;
		case 21:
			if (outGainValue >= -180 && outGainValue <= 180) {
				return true;
			}
			break;
		case 22:
			if (outGainValue >= 50 && outGainValue <= 20000) {
				return true;
			}
			break;
		case 23:
			if (outGainValue >= 50 && outGainValue <= 90) {
				return true;
			}
			break;
		case 24:
		case 25:
		case 26:
		case 27:
		case 28:
		case 29:
		case 30:
		case 31:
		case 32:
		case 33:
		case 34:
		case 35:
		case 36:
			if (outGainValue >= 50 && outGainValue <= 20000) {
				return true;
			}
			break;
		case 37:
		case 38:
		case 39:
		case 40:
		case 41:
		case 42:
		case 43:
		case 44:
		case 45:
		case 46:
		case 47:
		case 48:
		case 49:
			if (outGainValue >= 50 && outGainValue <= 90) {
				return true;
			}
			break;
		default:
			break;
		}
		return false;
	}

	OnCheckedChangeListener checkedListener_HPF = new OnCheckedChangeListener() {

		public void onCheckedChanged(CompoundButton buttonView,
				boolean isChecked) {

			setHPFEnable(isChecked);											// isChecked
			if (isChecked) {
				switch_hpf.setChecked(isChecked);
			}
		}

	};
	OnCheckedChangeListener checkedListener_PEQ = new OnCheckedChangeListener() {

		public void onCheckedChanged(CompoundButton buttonView,
				boolean isChecked) {

			saveChangePEQValue(0, buttonView, isChecked);// valuePEQ_PARAM[0] =
			setPEQEnable(isChecked);											// isChecked
			if (isChecked) {
				switch_PEQ.setChecked(isChecked);
			}
		}

	};
	
	OnCheckedChangeListener checkedListener_GEQ = new OnCheckedChangeListener() {

		public void onCheckedChanged(CompoundButton buttonView,
				boolean isChecked) {
			setGEQEnable(isChecked);	
			if (isChecked) {
				switch_GEQ.setChecked(isChecked);
			}
		}

	};

	public OnFocusChangeListener focusChangeListener_PEQBand_1 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(1, view, isFocus);
		}

	};

	public OnFocusChangeListener focusChangeListener_PEQFrequenceH_1 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(2, view, isFocus);
		}

	};

	public OnFocusChangeListener focusChangeListener_PEQFrequenceL_1 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(3, view, isFocus);
		}

	};

	public OnFocusChangeListener focusChangeListener_EQ_Value_1 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(4, view, isFocus);
		}

	};

	public OnFocusChangeListener focusChangeListener_PEQGain_1 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(5, view, isFocus);
		}

	};

	public OnFocusChangeListener focusChangeListener_PEQBand_2 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(6, view, isFocus);
		}

	};

	public OnFocusChangeListener focusChangeListener_PEQFrequenceH_2 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(7, view, isFocus);
		}

	};

	public OnFocusChangeListener focusChangeListener_PEQFrequenceL_2 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(8, view, isFocus);
		}

	};

	public OnFocusChangeListener focusChangeListener_EQ_Value_2 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(9, view, isFocus);
		}

	};

	public OnFocusChangeListener focusChangeListener_PEQGain_2 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(10, view, isFocus);
		}

	};

	public OnFocusChangeListener focusChangeListener_PEQBand_3 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(11, view, isFocus);
		}

	};

	public OnFocusChangeListener focusChangeListener_PEQFrequenceH_3 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(12, view, isFocus);
		}

	};

	public OnFocusChangeListener focusChangeListener_PEQFrequenceL_3 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(13, view, isFocus);
		}

	};

	public OnFocusChangeListener focusChangeListener_EQ_Value_3 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(14, view, isFocus);
		}

	};

	public OnFocusChangeListener focusChangeListener_PEQGain_3 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(15, view, isFocus);
		}

	};
	
	//GEQ
	public OnFocusChangeListener focusChangeListener_GEQ1 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(16, view, isFocus);
		}

	};
	public OnFocusChangeListener focusChangeListener_GEQ2 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(17, view, isFocus);
		}

	};

	public OnFocusChangeListener focusChangeListener_GEQ3 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(18, view, isFocus);
		}

	};

	public OnFocusChangeListener focusChangeListener_GEQ4 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(19, view, isFocus);
		}

	};

	public OnFocusChangeListener focusChangeListener_GEQ5 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(20, view, isFocus);
		}

	};
	
	//HPF
	public OnFocusChangeListener focusChangeListener_HPFGAIN = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(21, view, isFocus);
		}

	};
	public OnFocusChangeListener focusChangeListener_HPFFRE = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(22, view, isFocus);
		}

	};

	public OnFocusChangeListener focusChangeListener_HPFQVALUE = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(23, view, isFocus);
		}

	};
	
	//PEQPEQ
	public OnFocusChangeListener focusChangeListener_PEQFRE_BAND1 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(24, view, isFocus);
		}

	};
	public OnFocusChangeListener focusChangeListener_PEQFRE_BAND2 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(25, view, isFocus);
		}

	};
	public OnFocusChangeListener focusChangeListener_PEQFRE_BAND3 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(26, view, isFocus);
		}

	};
	public OnFocusChangeListener focusChangeListener_PEQFRE_BAND4 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(27, view, isFocus);
		}

	};
	public OnFocusChangeListener focusChangeListener_PEQFRE_BAND5 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(28, view, isFocus);
		}

	};
	public OnFocusChangeListener focusChangeListener_PEQFRE_BAND6 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(29, view, isFocus);
		}

	};
	public OnFocusChangeListener focusChangeListener_PEQFRE_BAND7 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(30, view, isFocus);
		}

	};
	public OnFocusChangeListener focusChangeListener_PEQFRE_BAND8 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(31, view, isFocus);
		}

	};
	public OnFocusChangeListener focusChangeListener_PEQFRE_BAND9 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(32, view, isFocus);
		}

	};
	public OnFocusChangeListener focusChangeListener_PEQFRE_BAND10 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(33, view, isFocus);
		}

	};
	public OnFocusChangeListener focusChangeListener_PEQFRE_BAND11 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(34, view, isFocus);
		}

	};
	public OnFocusChangeListener focusChangeListener_PEQFRE_BAND12 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(35, view, isFocus);
		}

	};
	public OnFocusChangeListener focusChangeListener_PEQFRE_BAND13 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(36, view, isFocus);
		}

	};
	public OnFocusChangeListener focusChangeListener_EQVALUE_BAND1 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(37, view, isFocus);
		}

	};
	public OnFocusChangeListener focusChangeListener_EQVALUE_BAND2 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(38, view, isFocus);
		}

	};
	public OnFocusChangeListener focusChangeListener_EQVALUE_BAND3 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(39, view, isFocus);
		}

	};
	public OnFocusChangeListener focusChangeListener_EQVALUE_BAND4 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(40, view, isFocus);
		}

	};
	public OnFocusChangeListener focusChangeListener_EQVALUE_BAND5 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(41, view, isFocus);
		}

	};
	public OnFocusChangeListener focusChangeListener_EQVALUE_BAND6 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(42, view, isFocus);
		}

	};
	public OnFocusChangeListener focusChangeListener_EQVALUE_BAND7 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(43, view, isFocus);
		}

	};
	public OnFocusChangeListener focusChangeListener_EQVALUE_BAND8 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(44, view, isFocus);
		}

	};
	public OnFocusChangeListener focusChangeListener_EQVALUE_BAND9 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(45, view, isFocus);
		}

	};
	public OnFocusChangeListener focusChangeListener_EQVALUE_BAND10 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(46, view, isFocus);
		}

	};
	public OnFocusChangeListener focusChangeListener_EQVALUE_BAND11 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(47, view, isFocus);
		}

	};
	public OnFocusChangeListener focusChangeListener_EQVALUE_BAND12 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(48, view, isFocus);
		}

	};
	public OnFocusChangeListener focusChangeListener_EQVALUE_BAND13 = new OnFocusChangeListener() {

		public void onFocusChange(View view, boolean isFocus) {
			saveChangePEQValue(49, view, isFocus);
		}

	};
	
	

	

	


	// ====================================================

	public OnKeyListener keyListener_PEQBand_1 = new OnKeyListener() {

		public boolean onKey(View view, int keycode, KeyEvent event) {

			EditText clickEditText = (EditText) view;

			EditTextInputErrorTip(clickEditText, 3, true);

			return false;

		}
	};

	public OnKeyListener keyListener_PEQBand_2 = new OnKeyListener() {

		public boolean onKey(View view, int keycode, KeyEvent event) {

			EditText clickEditText = (EditText) view;

			EditTextInputErrorTip(clickEditText, 3, true);

			return false;

		}
	};

	public OnKeyListener keyListener_PEQBand_3 = new OnKeyListener() {

		public boolean onKey(View view, int keycode, KeyEvent event) {

			EditText clickEditText = (EditText) view;

			EditTextInputErrorTip(clickEditText, 3, true);

			return false;

		}
	};

	public OnKeyListener keyListener_PEQFrequenceH_1 = new OnKeyListener() {

		public boolean onKey(View view, int keycode, KeyEvent event) {

			EditText clickEditText = (EditText) view;

			EditTextInputErrorTip(clickEditText, 3, true);

			return false;

		}
	};

	public OnKeyListener keyListener_PEQFrequenceH_2 = new OnKeyListener() {

		public boolean onKey(View view, int keycode, KeyEvent event) {

			EditText clickEditText = (EditText) view;

			EditTextInputErrorTip(clickEditText, 3, true);

			return false;

		}
	};

	public OnKeyListener keyListener_PEQFrequenceH_3 = new OnKeyListener() {

		public boolean onKey(View view, int keycode, KeyEvent event) {

			EditText clickEditText = (EditText) view;

			EditTextInputErrorTip(clickEditText, 3, true);

			return false;

		}
	};

	public OnKeyListener keyListener_PEQFrequenceL_1 = new OnKeyListener() {

		public boolean onKey(View view, int keycode, KeyEvent event) {

			EditText clickEditText = (EditText) view;

			EditTextInputErrorTip(clickEditText, 3, true);

			return false;

		}
	};

	public OnKeyListener keyListener_PEQFrequenceL_2 = new OnKeyListener() {

		public boolean onKey(View view, int keycode, KeyEvent event) {

			EditText clickEditText = (EditText) view;

			EditTextInputErrorTip(clickEditText, 3, true);

			return false;

		}
	};

	public OnKeyListener keyListener_PEQFrequenceL_3 = new OnKeyListener() {

		public boolean onKey(View view, int keycode, KeyEvent event) {

			EditText clickEditText = (EditText) view;

			EditTextInputErrorTip(clickEditText, 3, true);

			return false;

		}
	};

	public OnKeyListener keyListener_EQ_Value_1 = new OnKeyListener() {

		public boolean onKey(View view, int keycode, KeyEvent event) {

			EditText clickEditText = (EditText) view;

			EditTextInputErrorTip(clickEditText, 3, true);

			return false;

		}
	};

	public OnKeyListener keyListener_EQ_Value_2 = new OnKeyListener() {

		public boolean onKey(View view, int keycode, KeyEvent event) {

			EditText clickEditText = (EditText) view;

			EditTextInputErrorTip(clickEditText, 3, true);

			return false;

		}
	};

	public OnKeyListener keyListener_EQ_Value_3 = new OnKeyListener() {

		public boolean onKey(View view, int keycode, KeyEvent event) {

			EditText clickEditText = (EditText) view;

			EditTextInputErrorTip(clickEditText, 3, true);

			return false;

		}
	};

	public OnKeyListener keyListener_PEQGain_1 = new OnKeyListener() {

		public boolean onKey(View view, int keycode, KeyEvent event) {

			EditText clickEditText = (EditText) view;

			EditTextInputErrorTip(clickEditText, 3, true);

			return false;

		}
	};

	public OnKeyListener keyListener_PEQGain_2 = new OnKeyListener() {

		public boolean onKey(View view, int keycode, KeyEvent event) {

			EditText clickEditText = (EditText) view;

			EditTextInputErrorTip(clickEditText, 3, true);

			return false;

		}
	};

	public OnKeyListener keyListener_PEQGain_3 = new OnKeyListener() {

		public boolean onKey(View view, int keycode, KeyEvent event) {

			EditText clickEditText = (EditText) view;

			EditTextInputErrorTip(clickEditText, 3, true);

			return false;

		}
	};
	// ============================================================================================================
	// ================================== MIC
	// =========================================================
	// ============================================================================================================
	
	
	public boolean EditTextInputErrorTip(EditText clickEditText, int charCount,
			boolean flag) {

		String text = clickEditText.getText().toString().trim();
		// clickEditText.setTextColor(Color.WHITE);
		if ((text.length() > charCount)
				|| (text.startsWith("0") && text.length() > 1 && flag)) {

			Drawable draw = getResources().getDrawable(
					android.R.drawable.ic_delete);
			draw.setBounds(0, 0, 30, 30); // 必须设置大小，否则不显示
			clickEditText.setError("The input data is out of order!", draw);
			return true;
			// Toast.makeText(AQService.this, "输入的数据有误!",
			// Toast.LENGTH_SHORT).show();
		}
		return false;
	}
	
	// base data

	private static final String TAG = "AQ";
	// private TabHost tabHost;

	// ap data

	// aq.ini
	private static final String[] sectionNmaes = { 
		"IniVersion",                            //0
		"SourceSpeakerPrescaler",                //1
		"SoundModeSetting",                      //2
		"Sound_NonLinear_Source",                //3
		"Sound_NonLinear_Source_Market",          //4
		"VIRTUAL_SURROUND",                       //5
		"AVOutPathGain",                         //6
		"SPDIFOutPathGain",                      //7
		"LimiterThreshold",                       //8
		"PEQ_PARAM",                              //9
		"AUDIO_NR_THR"                            //10     
		 }; // count=11

	private static final String[] keyIniVersion = { 
	"AQID", 
	"Ver" 
	};
	private static String[] valueIniVersion = { 
	"CHAQ", 
	"001" 
	};

	private static final String[] keySourceSpeakerPrescaler = {
		"MainSpeaker_Prescale_ATV", 
		"MainSpeaker_Prescale_DTV",
		"MainSpeaker_Prescale_AV", 
		"MainSpeaker_Prescale_YPBPR",
		"MainSpeaker_Prescale_PC", 
		"MainSpeaker_Prescale_HDMI",
		"MainSpeaker_Prescale_USB", 
		"MainSpeaker_Prescale_NET" 
		};
private static String[] valueSourceSpeakerPrescaler = { 
		"0x19", 
		"0x19",
		"0x19", 
		"0x19", 
		"0x19", 
		"0x19", 
		"0x19", 
		"0x19" 
		};

private static final String[] keySoundModeSetting = {
	"Sound_mode_standard", 
	"Sound_mode_music",    
	"Sound_mode_movie", 
	"Sound_mode_sports",
	};

//    private static final String[] keySoundModeSetting = {
//	"Sound_mode_standard", 
//	"Sound_mode_movie", 
//	"Sound_mode_umax",
//	"Sound_mode_read",  
//	"Sound_mode_music",    
//	"Sound_mode_sports",
//	"Sound_mode_game"};
	
//	private static String[] valueSoundModeSetting = { 
//			"{50,50,50,50,50}",
//			"{55,45,40,60,70}", 
//			"{60,40,40,60,70}",
//			 "{45,50,45,60,65}",
//			"{60,40,40,60,70}",
//			 "{40,35,35,70,75}",
//			  "{40,35,35,70,75}" };
	
	private static String[] valueSoundModeSetting = { 
		"{50,50,50,50,50}",
		"{60,40,40,60,70}",
		"{55,45,40,60,70}",
		 "{40,35,35,70,75}",
		 "{40,35,35,70,75}",
		 "{40,35,35,70,75}",
		 "{40,35,35,70,75}",
	 };
	
	private static final String[] keySound_NonLinear_Source = {
		"Sound_NonLinear_ATV", 
		"Sound_NonLinear_DTV", 
		"Sound_NonLinear_AV",
		"Sound_NonLinear_YPBPR", 
		"Sound_NonLinear_PC",
		"Sound_NonLinear_HDMI", 
		"Sound_NonLinear_USB",
		"Sound_NonLinear_NET" 
		};
private static String[] valueSound_NonLinear_Source = {
		"{0x2EE2,0x2630,0x1BB0,0x145A,0x0E8C,0x09D0,0x070A,0x046C,0x039A}",
		"{0x2EE2,0x2630,0x1BB0,0x145A,0x0E8C,0x09D0,0x070A,0x046C,0x039A}",
		"{0x2EE2,0x2E00,0x1D40,0x1522,0x0EF0,0x0A98,0x07A0,0x0502,0x0462}",
		"{0x2EE2,0x2E00,0x1D40,0x1522,0x0EF0,0x0A98,0x07A0,0x0502,0x0462}",
		"{0x2EE2,0x2E00,0x1D40,0x1522,0x0EF0,0x0A98,0x07A0,0x0502,0x0462}",
		"{0x2EE2,0x2E00,0x1D40,0x1522,0x0EF0,0x0A98,0x07A0,0x0502,0x0462}",
		"{0x2EE2,0x2E00,0x1D40,0x1522,0x0EF0,0x0A98,0x07A0,0x0502,0x0462}",
		"{0x2EE2,0x2E00,0x1D40,0x1522,0x0EF0,0x0A98,0x07A0,0x0502,0x0462}" 
		};

private static final String[] keySound_NonLinear_Source_Market = {
		"Sound_NonLinear_ATV", 
		"Sound_NonLinear_DTV", 
		"Sound_NonLinear_AV",
		"Sound_NonLinear_YPBPR", 
		"Sound_NonLinear_PC",
		"Sound_NonLinear_HDMI", 
		"Sound_NonLinear_USB",
		"Sound_NonLinear_NET" 
		};

private static String[] valueSound_NonLinear_Source_Market = {
		"{0x2EE2,0x2630,0x1BB0,0x145A,0x0E8C,0x09D0,0x070A,0x046C,0x039A}",
		"{0x2EE2,0x2630,0x1BB0,0x145A,0x0E8C,0x09D0,0x070A,0x046C,0x039A}",
		"{0x2EE2,0x2E00,0x1D40,0x1522,0x0EF0,0x0A98,0x07A0,0x0502,0x0462}",
		"{0x2EE2,0x2E00,0x1D40,0x1522,0x0EF0,0x0A98,0x07A0,0x0502,0x0462}",
		"{0x2EE2,0x2E00,0x1D40,0x1522,0x0EF0,0x0A98,0x07A0,0x0502,0x0462}",
		"{0x2EE2,0x2E00,0x1D40,0x1522,0x0EF0,0x0A98,0x07A0,0x0502,0x0462}",
		"{0x2EE2,0x2E00,0x1D40,0x1522,0x0EF0,0x0A98,0x07A0,0x0502,0x0462}",
		"{0x2EE2,0x2E00,0x1D40,0x1522,0x0EF0,0x0A98,0x07A0,0x0502,0x0462}" 
		};


	private static final String[] keyVIRTUAL_SURROUND = {
			"SOUND_SUR_MTK_CLARITY", 
			"SOUND_SUR_MTK_WIDTH",
			"SOUND_SUR_MTK_LRGAIN", 
			"SOUND_SUR_MTK_XTALK",
			"SOUND_SUR_MTK_OUTPUT_GAIN",
			 "SOUND_SUR_MTK_BASS_GAIN",
			"SOUND_SUR_MTK_FO", 
			"SOUND_SUR_MST_XA", 
			"SOUND_SUR_MST_XB",
			"SOUND_SUR_MST_XK", 
			"SOUND_SUR_MST_LPFGain" };
	private static String[] valueVIRTUAL_SURROUND = { 
	"0x460000", 
	"0x460000",
			"0x300000", 
			"0x70000", 
			"0x50000", 
			"0x0", 
			"0x7f4300", 
			"0x0", 
			"0x3",
			"0x0", 
			"0x2" 
			};

	private static final String[] keyAVOutPathGain = {
		"ATVAvoutGain", 
		"DTVAvoutGain",
		"AVAvoutGain", 
		"YPbPrAvoutGain",
		"VGAAvoutGain", 
		"HDMIAvoutGain",
		"MEDIAAvoutGain",
		"NETAvoutGain" 
		};
	private static String[] valueAVOutPathGain = { 
		"0", 
		"0", 
		"0", 
		"0", 
		"0",
		"0", 
		"0" , 
		"0"
		};
	private static final String[] keySPDIFOutPathGain = {
		"ATVSpdifGain", 
		"DTVSpdifGain",
		"AVSpdifGain", 
		"YPbPrSpdifGain",
		"VGASpdifGain", 
		"HDMISpdifGain",
		"MEDIASpdifGain",
		"NETSpdifGain" 
		};
	private static String[] valueSPDIFOutPathGain = { 
		"15", 
		"15", 
		"15", 
		"15", 
		"15",
		"15", 
		"15", 
		"15"
		};

//	private static final String[] keyLimiterThreshold = { "AudioLimiterThreshold" };
//	private static String[] valueLimiterThreshold = { "0x70000" };
	
	private static final String[] keyLimiterThreshold = { 
		"DRC_ENABLE" ,
		"AudioLimiterThreshold"
		
		};
	private static String[] valueLimiterThreshold = { 
		"TRUE",
		"0x70000"
	     };


	private static final String[] keyPEQ_PARAM = { "PEQ_ENABLE",
			"Sound_PEQ_Band1_Param", 
			"Sound_PEQ_Band2_Param",
			"Sound_PEQ_Band3_Param" 
			};
	private static String[] valuePEQ_PARAM = { 
	"FALSE", 
	"{0,10,0,160,120}",
			"{1,10,0,160,120}", 
			"{2,10,0,160,120}" };
	private int[] PEQ1 = {0,0,0,0,0};
	private int[] PEQ2 = {1,0,0,0,0};
	private int[] PEQ3 = {2,0,0,0,0};
	private int[] GEQ = {0,0,0,0,0};
	private int[] HPF = {0,0,0};

	private static final String[] keyAUDIO_NR_THR = { "audio_nr_threshold" };
	private static String[] valueAUDIO_NR_THR = { "0x60" };

	Button ButtonOpencfgFile, ButtonTransferFile, ButtonExportData;
	TabWidget tabWidget;
	View tab0, tab1, tab2, tab3, tab4, tab5, tab6, tab7;

	private static String prevStr;
	private static EditText focusEditText;
	private static boolean switchFocus = true;
	private static boolean bFocusTab = true;
	
	private int getSourceIDByName(String sourceName){
		for(int i = 0; i < inputList.size(); i++){
			if(sourceName.equals(inputList.get(i).getSourceName())){
				return inputList.get(i).getId();
			}
		}
		return -1;
	}
	
	private void initSourceName(){
		
		int compositeNum = 0;
        int size = MtkTvInputSource.getInstance().getInputSourceTotalNumber();
        Log.d(TAG,"size = "+size);
        for (int i = 0; i < size; i++){
            MtkTvInputSource.InputSourceRecord record = new MtkTvInputSource.InputSourceRecord();
            MtkTvInputSource.getInstance().getInputSourceRecbyidx(i, record);

            inputList.add(record);
            String sourceTypeName;
            sourceTypeName = record.getInputType().name();

            Log.d(TAG,"sourceTypeName = "+sourceTypeName);
            if (TextUtils.isEmpty(sourceTypeName)) {
                continue;
            } else {
                
                    if (sourceTypeName.equalsIgnoreCase("TV")) {
                    	if(mUiSourceList.contains("DTV")){
	                	    mUiSourceList.add("ATV");
	                	    sourceMap.put("ATV", TVUri);
	                    } else {
	                    	mUiSourceList.add("DTV");
	                 	    sourceMap.put("DTV", TVUri);
	                    }
//                	  mUiSourceList.add("TV");
//            	      sourceMap.put("TV", TVUri);
                    } else if (sourceTypeName.equalsIgnoreCase("COMPOSITE")) {
                        compositeNum = record.getInternalIdx();
                        if (compositeNum > 0) {// modify string for idx=0
                            if (compositeNum == 1) {
                                mUiSourceList.set(mUiSourceList.size() - 1,
                                        "Composite " + compositeNum);
                            }
                            mUiSourceList
                                    .add("Composite " + (compositeNum + 1));
                        } else {
                            mUiSourceList.add("Composite");
                            sourceMap.put("Composite",CompositeUri);
                        }
                    } else if (sourceTypeName.equalsIgnoreCase("COMPONENT")) {
                        mUiSourceList.add("Component");
                        sourceMap.put("Component", ComponentUri);
                    } else if (sourceTypeName.equalsIgnoreCase("VGA")) {
                        mUiSourceList.add("VGA");
                        sourceMap.put("VGA", VgaUri);
                    } else if (sourceTypeName.equalsIgnoreCase("HDMI")) {
//                        if ((record.getInternalIdx() + 1) == mTvInputSource.getMhlPortNum()) {// mTvInputSource.getMhlPortNum()
//                            mUiSourceList.add("HDMI "
//                                    + (record.getInternalIdx() + 1) + " / MHL");
//                        } else {
                            mUiSourceList.add("HDMI "
                                    + (record.getInternalIdx() + 1));
//                        }
                          if(record.getInternalIdx() + 1 == 1 ){
                        	  sourceMap.put("HDMI 1", HDMI1Uri);
                          } else if(record.getInternalIdx() + 1 == 2){
                        	  sourceMap.put("HDMI 2", HDMI2Uri);
                          } else if(record.getInternalIdx() + 1 == 3){
                        	  sourceMap.put("HDMI 3", HDMI3Uri);
                          }
                    } else if (sourceTypeName.equalsIgnoreCase("RESERVED")) {
                        mUiSourceList.add("RESERVED");
                    } else if (sourceTypeName.equalsIgnoreCase("SCART")) {
                        mUiSourceList.add("SCART");
                    } else if (sourceTypeName.equalsIgnoreCase("SVIDEO")) {
                        mUiSourceList.add("SVIDEO");
                    }
                }
        }
	}
	
	public String getSourceIdByName(String name) {

		return sourceMap.get(name);
//        int size = MtkTvInputSource.getInstance().getInputSourceTotalNumber();
//        for (int i = 0; i < size; i++) {
//            MtkTvInputSource.InputSourceRecord record = inputList.get(i);
//            String tmpName = "";
//            tmpName = record.getInputType().name();
//            if (tmpName == null) {
//                tmpName = "";
//            }
//            // name.toLowerCase();
//            // tmpName.toLowerCase();
//            if (name.equalsIgnoreCase(tmpName)) {
//                return sourceMap.get(tmpName);//record.getId();
//            }
//
//
//            if (name.toUpperCase().startsWith(tmpName)) {// for HDMI
//                if (name.contains(String.valueOf(record.getInternalIdx() + 1))) {
//                    return sourceMap.get(tmpName);//record.getId();
//                }
//            }
//        }
//
//        return -1;
	}
	
	private MTKTV_FAPI_INI_TYPE_AUDIO_ENUM selectBasicSndIniPath(EnumSoundMode soundMode) {
        MTKTV_FAPI_INI_TYPE_AUDIO_ENUM eRetIniPath = MTKTV_FAPI_INI_TYPE_AUDIO_ENUM.E_MTK_FAPI_INI_TYPE_AUDIO_MAX;
        switch(soundMode) {
            case E_FAPI_AUD_SOUND_MODE_DEFAULT: {
                eRetIniPath = MTKTV_FAPI_INI_TYPE_AUDIO_ENUM.E_MTK_FAPI_INI_TYPE_BASIC_DEFAULT_SOUND_EFFECT;
                break;
            }
            case E_FAPI_AUD_SOUND_MODE_MOVIE: {
                eRetIniPath = MTKTV_FAPI_INI_TYPE_AUDIO_ENUM.E_MTK_FAPI_INI_TYPE_BASIC_MOVIE_SOUND_EFFECT;
                break;
            }
            case E_FAPI_AUD_SOUND_MODE_MUSIC: {
                eRetIniPath = MTKTV_FAPI_INI_TYPE_AUDIO_ENUM.E_MTK_FAPI_INI_TYPE_BASIC_MUSIC_SOUND_EFFECT;
                break;
            }
            case E_FAPI_AUD_SOUND_MODE_NEWS: {
                eRetIniPath = MTKTV_FAPI_INI_TYPE_AUDIO_ENUM.E_MTK_FAPI_INI_TYPE_BASIC_NEWS_SOUND_EFFECT;
                break;
            }
            case E_FAPI_AUD_SOUND_MODE_SPORTS: {
                eRetIniPath = MTKTV_FAPI_INI_TYPE_AUDIO_ENUM.E_MTK_FAPI_INI_TYPE_BASIC_SPORTS_SOUND_EFFECT;
                break;
            }
            case E_FAPI_AUD_SOUND_MODE_STANDARD: {
                eRetIniPath = MTKTV_FAPI_INI_TYPE_AUDIO_ENUM.E_MTK_FAPI_INI_TYPE_BASIC_STANDARD_SOUND_EFFECT;
                break;
            }
            case E_FAPI_AUD_SOUND_MODE_USER: {
                eRetIniPath = MTKTV_FAPI_INI_TYPE_AUDIO_ENUM.E_MTK_FAPI_INI_TYPE_BASIC_USER_SOUND_EFFECT;
                break;
            }
            case E_FAPI_AUD_SOUND_MODE_VIVID: {
                eRetIniPath = MTKTV_FAPI_INI_TYPE_AUDIO_ENUM.E_MTK_FAPI_INI_TYPE_BASIC_VIVID_SOUND_EFFECT;
                break;
            }
            default: {
                Log.e(TAG, "Unknown sound type");
                eRetIniPath = MTKTV_FAPI_INI_TYPE_AUDIO_ENUM.E_MTK_FAPI_INI_TYPE_AUDIO_MAX;
                break;
            }
        }
        return eRetIniPath;
	}
	
	private void saveDrcSwitchToAllSource(boolean isOpen){
		AudioInputSource curAudioSource = MtkTvFApiAudio.getInstance().getCurrentAudioSrc();
		BasicSoundEnableStatus sndStatus = new BasicSoundEnableStatus();
		
	    MtkTvFApiAudio.getInstance().setCurrentAudioSrc(AudioInputSource.ATV);
		MtkTvFApiAudio.getInstance().getBasicSoundEnableStatus(EnumSoundMode.values()[SOUND_MODE_ID], sndStatus);
		if(isOpen == true){
				sndStatus.bDrcEnable = 1;
		} else {
				sndStatus.bDrcEnable = 0;
		}
		MtkTvFApiAudio.getInstance().enableBasicSoundEffect(EnumSoundMode.values()[SOUND_MODE_ID], sndStatus);
		
		 MtkTvFApiAudio.getInstance().setCurrentAudioSrc(AudioInputSource.DTV);
			MtkTvFApiAudio.getInstance().getBasicSoundEnableStatus(EnumSoundMode.values()[SOUND_MODE_ID], sndStatus);
			if(isOpen == true){
					sndStatus.bDrcEnable = 1;
			} else {
					sndStatus.bDrcEnable = 0;
			}
			MtkTvFApiAudio.getInstance().enableBasicSoundEffect(EnumSoundMode.values()[SOUND_MODE_ID], sndStatus);
			
		MtkTvFApiAudio.getInstance().setCurrentAudioSrc(AudioInputSource.HDMI);
		MtkTvFApiAudio.getInstance().getBasicSoundEnableStatus(EnumSoundMode.values()[SOUND_MODE_ID], sndStatus);
		if(isOpen == true){
				sndStatus.bDrcEnable = 1;
		} else {
				sndStatus.bDrcEnable = 0;
		}
		MtkTvFApiAudio.getInstance().enableBasicSoundEffect(EnumSoundMode.values()[SOUND_MODE_ID], sndStatus);
		
		 MtkTvFApiAudio.getInstance().setCurrentAudioSrc(AudioInputSource.CVBS);
			MtkTvFApiAudio.getInstance().getBasicSoundEnableStatus(EnumSoundMode.values()[SOUND_MODE_ID], sndStatus);
			if(isOpen == true){
					sndStatus.bDrcEnable = 1;
			} else {
					sndStatus.bDrcEnable = 0;
			}
		MtkTvFApiAudio.getInstance().enableBasicSoundEffect(EnumSoundMode.values()[SOUND_MODE_ID], sndStatus);
		
		 MtkTvFApiAudio.getInstance().setCurrentAudioSrc(AudioInputSource.MM);
			MtkTvFApiAudio.getInstance().getBasicSoundEnableStatus(EnumSoundMode.values()[SOUND_MODE_ID], sndStatus);
			if(isOpen == true){
				sndStatus.bDrcEnable = 1;
			} else {
				sndStatus.bDrcEnable = 0;
			}
		MtkTvFApiAudio.getInstance().enableBasicSoundEffect(EnumSoundMode.values()[SOUND_MODE_ID], sndStatus);
		
//		MtkTvFApiAudio.getInstance().setCurrentAudioSrc(curAudioSource);
		setCurrentAudioSrcByinputsource();
		
	}
	
	private void saveDrcLimiterToAllSource(int value){
		Log.v("lhtest","saveDrcLimiterToAllSource");
//		AudioInputSource curAudioSource = MtkTvFApiAudio.getInstance().getCurrentAudioSrc();
		setCurrentAudioSrcByinputsource();
		SoundEffectParams argSoundEffect = new SoundEffectParams();
		
//	    MtkTvFApiAudio.getInstance().setCurrentAudioSrc(AudioInputSource.ATV);
//	    MtkTvFApiAudio.getInstance().getAudioIniBasicSndParams(EnumSoundMode.values()[SOUND_MODE_ID],argSoundEffect);
//		argSoundEffect.DrcAllBand_TargetLevel = value;
//		MtkTvFApiAudio.getInstance().setBasicSoundEffect(EnumSoundMode.values()[SOUND_MODE_ID], EnumBasicSoundType.E_FAPI_AUD_BASIC_SND_DRC, argSoundEffect);
//		
//		 MtkTvFApiAudio.getInstance().setCurrentAudioSrc(AudioInputSource.DTV);
//		 MtkTvFApiAudio.getInstance().getAudioIniBasicSndParams(EnumSoundMode.values()[SOUND_MODE_ID],argSoundEffect);
//		argSoundEffect.DrcAllBand_TargetLevel = value;
//	    MtkTvFApiAudio.getInstance().setBasicSoundEffect(EnumSoundMode.values()[SOUND_MODE_ID], EnumBasicSoundType.E_FAPI_AUD_BASIC_SND_DRC, argSoundEffect);
//			
//		MtkTvFApiAudio.getInstance().setCurrentAudioSrc(AudioInputSource.HDMI);
//		MtkTvFApiAudio.getInstance().getAudioIniBasicSndParams(EnumSoundMode.values()[SOUND_MODE_ID],argSoundEffect);
//		argSoundEffect.DrcAllBand_TargetLevel = value;
//		MtkTvFApiAudio.getInstance().setBasicSoundEffect(EnumSoundMode.values()[SOUND_MODE_ID], EnumBasicSoundType.E_FAPI_AUD_BASIC_SND_DRC, argSoundEffect);
//		
//		 MtkTvFApiAudio.getInstance().setCurrentAudioSrc(AudioInputSource.CVBS);
//		 MtkTvFApiAudio.getInstance().getAudioIniBasicSndParams(EnumSoundMode.values()[SOUND_MODE_ID],argSoundEffect);
//		argSoundEffect.DrcAllBand_TargetLevel = value;
//		MtkTvFApiAudio.getInstance().setBasicSoundEffect(EnumSoundMode.values()[SOUND_MODE_ID], EnumBasicSoundType.E_FAPI_AUD_BASIC_SND_DRC, argSoundEffect);
//		
//		 MtkTvFApiAudio.getInstance().setCurrentAudioSrc(AudioInputSource.MM);
		 MtkTvFApiAudio.getInstance().getAudioIniBasicSndParams(EnumSoundMode.values()[SOUND_MODE_ID],argSoundEffect);
		argSoundEffect.DrcAllBand_TargetLevel = value;
		MtkTvFApiAudio.getInstance().setBasicSoundEffect(EnumSoundMode.values()[SOUND_MODE_ID], EnumBasicSoundType.E_FAPI_AUD_BASIC_SND_DRC, argSoundEffect);
		
//		MtkTvFApiAudio.getInstance().setCurrentAudioSrc(curAudioSource);
		
	}
	private void setCurrentAudioSrcByinputsource() {
		Log.v("lhtest","setCurrentAudioSrcByinputsource");
		String currentSource = MtkTvInputSourceBase.INPUT_TYPE_ATV;
		AudioInputSource curAudioSource = MtkTvFApiAudio.getInstance().getCurrentAudioSrc();;
		try {
			currentSource = MtkTvInputSource.getInstance().getCurrentInputSourceName();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Log.v("lhtest","setCurrentAudioSrcByinputsource currentSource="+currentSource);
		if(currentSource.equals("ATV")){
			curAudioSource = AudioInputSource.ATV;
		} else if(currentSource.equals("DTV")){
			curAudioSource = AudioInputSource.DTV;
		} else if(currentSource.equals("Composite")){
			curAudioSource = AudioInputSource.CVBS;
		}  else if(currentSource.equals("HDMI 1") 
				|| currentSource.equals("HDMI 2")
				|| currentSource.equals("HDMI 3")
				|| currentSource.equals("HDMI 4")){
			curAudioSource = AudioInputSource.HDMI;
		} 
		MtkTvFApiAudio.getInstance().setCurrentAudioSrc(curAudioSource);
	}
	
//	public static Activity findActivity(Context context) {
//        if (context instanceof Activity) {
//            return (Activity) context;
//        }
//        if (context instanceof ContextWrapper) {
//            ContextWrapper wrapper = (ContextWrapper) context;
//            return findActivity(wrapper.getBaseContext());
//        } else {
//            return null;
//        }
//    }

    
}// Service

